我正在关注this flask教程。在学习数据库迁移的同时,我从教程->复制了此代码

#!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


谁能告诉我这些错误的含义以及如何解决?

最佳答案

我通过安装以下程序解决了该问题:

SQLAlchemy 0.7.9
sqlalchemy迁移0.7.2

(最新版本无效,但这些旧版本有效)

关于python - ValueError:太多值无法解包,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31097685/

10-10 14:36