Я занимаюсь разработкой API с колбой и ее различными расширениями.У меня есть база данных с настройкой подключения к локальной базе данных MySQL.Когда я пытаюсь выполнить db.drop_all()
, возникает следующая ошибка:
Traceback (most recent call last):
File "/usr/lib/python3.6/code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 2, in <module>
File "/home/zahessi/.local/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 971, in drop_all
self._execute_for_all_tables(app, bind, 'drop_all')
File "/home/zahessi/.local/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 955, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/sql/schema.py", line 4032, in drop_all
tables=tables)
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1940, in _run_visitor
conn._run_visitor(visitorcallable, element, **kwargs)
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1549, in _run_visitor
**kwargs).traverse_single(element)
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/sql/visitors.py", line 121, in traverse_single
return meth(obj, **kw)
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/sql/ddl.py", line 909, in visit_metadata
self.traverse_single(fkc)
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/sql/visitors.py", line 121, in traverse_single
return meth(obj, **kw)
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/sql/ddl.py", line 971, in visit_foreign_key_constraint
self.connection.execute(DropConstraint(constraint))
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 948, in execute
return meth(self, multiparams, params)
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/sql/ddl.py", line 68, in _execute_on_connection
return connection._execute_ddl(self, multiparams, params)
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1003, in _execute_ddl
if not self.schema_for_object.is_default else None)
File "<string>", line 1, in <lambda>
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line 442, in compile
return self._compiler(dialect, bind=bind, **kw)
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/sql/ddl.py", line 26, in _compiler
return dialect.ddl_compiler(dialect, self, **kw)
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 219, in __init__
self.string = self.process(self.statement, **compile_kwargs)
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 245, in process
return obj._compiler_dispatch(self, **kwargs)
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/sql/visitors.py", line 81, in _compiler_dispatch
return meth(self, **kw)
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/dialects/mysql/base.py", line 1312, in visit_drop_constraint
const = self.preparer.format_constraint(constraint)
File "<string>", line 1, in <lambda>
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 3151, in format_constraint
return self.quote(constraint.name)
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 3101, in quote
if self._requires_quotes(ident):
File "/home/zahessi/.local/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 3072, in _requires_quotes
lc_value = value.lower()
AttributeError: 'NoneType' object has no attribute 'lower'
Единственное, что помогает, - это отбросить всю базу данных, а затем снова создать ее.Но я делаю это только через CLI, поэтому в коде нет обычного способа сделать это.
РЕДАКТИРОВАТЬ: БД инициализируется на этой фабрике:
def create_app():
from flask import Flask
from models import db, ma
from flask_compress import Compress
from sqlathanor import initialize_flask_sqlathanor
# initialization
app = Flask(__name__)
app.config.from_object('config.Config')
db.init_app(app)
ma.init_app(app)
initialize_flask_sqlathanor(db)
Compress(app)
# blueprints
from blueprints.users_crud.views import MANAGE_USERS_BLUE
from blueprints.projects_tasks.views import PROJECTS_BLUE
app.register_blueprint(MANAGE_USERS_BLUE)
app.register_blueprint(PROJECTS_BLUE)
return app, db
Поскольку я проверял ошибкуне зависит от расширений, названных здесь.Моя цель - удалить все таблицы.