每次我更新我的模型时,我都必须删除并重新初始化数据库。
./manage.py db init
然后初始
./manage.py db migrate
工作,但每个后续都./manage.py db migrate
失败并出现以下错误:
INFO [alembic.migration] Context impl SQLiteImpl.
INFO [alembic.migration] Will assume non-transactional DDL.
Traceback (most recent call last):
File "manage.py", line 110, in <module>
manager.run()
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages
/flask_script/__init__.py", line 405, in run
result = self.handle(sys.argv[0], sys.argv[1:])
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages
/flask_script/__init__.py", line 384, in handle
return handle(app, *positional_args, **kwargs)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages
/flask_script/commands.py", line 145, in handle
return self.run(*args, **kwargs)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages
/flask_migrate/__init__.py", line 80, in migrate
command.revision(config, message, autogenerate = True, sql = sql)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages /alembic/command.py", line 97, in revision
script.run_env()
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages /alembic/script.py", line 199, in run_env
util.load_python_file(self.dir, 'env.py')
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/util.py", line 199, in load_python_file
module = load_module(module_id, path)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/compat.py", line 49, in load_module
return machinery.SourceFileLoader(module_id, path).load_module()
File "<frozen importlib._bootstrap>", line 539, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1614, in load_module
File "<frozen importlib._bootstrap>", line 596, in _load_module_shim
File "<frozen importlib._bootstrap>", line 1220, in load
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "migrations/env.py", line 72, in <module>
run_migrations_online()
File "migrations/env.py", line 65, in run_migrations_online
context.run_migrations()
File "<string>", line 7, in run_migrations
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/environment.py", line 652, in run_migrations
self.get_context().run_migrations(**kw)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages /alembic/migration.py", line 210, in run_migrations
self):
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/command.py", line 83, in retrieve_migrations
autogen._produce_migration_diffs(context, template_args, imports)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/autogenerate/api.py", line 143, in _produce_migration_diffs
autogen_context, object_filters, include_schemas)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/autogenerate/api.py", line 198, in _produce_net_changes
inspector, metadata, diffs, autogen_context)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/autogenerate/compare.py", line 69, in _compare_tables
diffs, autogen_context, inspector)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/autogenerate/compare.py", line 223, in _compare_indexes_and_uniques
metadata_indexes
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/ddl/sqlite.py", line 56, in correct_for_autogen_constraints
conn_uniques.remove(idx)
NameError: name 'conn_uniques' is not defined
我使用 SQLite3 数据库。我将模型拆分为多个文件,但将它们放在一个文件中,但没有帮助。我也试过升级flask-migrate
,flask-sqlalchemy
等包也无济于事。有什么问题?
更新: 我正在使用 Alembic 版本 0.6.2