我正在关注this烧瓶教程。在了解数据库迁移的同时,我从教程>
中复制了此代码#!flask/bin/python
from migrate.versioning import api
from app import db
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
migration = SQLALCHEMY_MIGRATE_REPO + ('/versions/%03d_migration.py' % (v+1))
tmp_module = imp.new_module('old_model')
old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
exec(old_model, tmp_module.__dict__)
script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
open(migration, "wt").write(script)
api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
print('New migration saved as ' + migration)
print('Current database version: ' + str(v))
当我运行此代码时,它会向我显示这些错误 - >
Traceback (most recent call last):
File "./db_migrate.py", line 12, in <module>
script =api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
File "<string>", line 2, in make_update_script_for_model
File "/home/paladin/microblog/flask/local/lib/python2.7/site-packages/migrate/versioning/util/__init__.py", line 90, in catch_known_errors
return f(*a, **kw)
File "<string>", line 2, in make_update_script_for_model
File "/home/paladin/microblog/flask/local/lib/python2.7/site-packages/migrate/versioning/util/__init__.py", line 160, in with_engine
return f(*a, **kw)
File "/home/paladin/microblog/flask/local/lib/python2.7/site-packages/migrate/versioning/api.py", line 321, in make_update_script_for_model
engine, oldmodel, model, repository, **opts)
File "/home/paladin/microblog/flask/local/lib/python2.7/site-packages/migrate/versioning/script/py.py", line 70, in make_update_script_for_model
genmodel.ModelGenerator(diff,engine).genB2AMigration()
File "/home/paladin/microblog/flask/local/lib/python2.7/site-packages/migrate/versioning/genmodel.py", line 219, in genB2AMigration
for modelCol, databaseCol, modelDecl, databaseDecl in td.columns_different:
ValueError: too many values to unpack
有谁能告诉我这些错误是什么意思以及如何解决它们?
答案 0 :(得分:1)
我通过安装以下方法在我的环境中解决了这个问题:
SQLAlchemy 0.7.9 sqlalchemy-migrate 0.7.2
(最新版本不起作用,但这些旧版本确实如此)