每次更新模型时,我都必须删除并重新初始化数据库。
./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
答案 0 :(得分:1)
这真的很奇怪,但是Alembic的0.6.x版本中有一些似乎有这个未定义的符号。
错误在0.6.7版本中得到纠正。以下是显示此行如何更正的提交:https://github.com/zzzeek/alembic/commit/ead05ce48d40d4235b2395972fd1a6efb96d414c
非常确定如果升级到0.6.7或更高版本,问题将得到解决。