SQLAlchemy 做migration的时候 ValueError: too many values to unpack
我在做数据库迁移的时候,使用sqlalchemy,出现一个问题
Traceback (most recent call last): File "/Volumes/Spano/Dropbox/Dropbox/eclipse-workspace/CAUDLE/src/caudle/caudle/db_migrate.py", line 11, 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 "/Users/johncaine/anaconda/lib/python2.7/site-packages/migrate/versioning/util/__init__.py", line 89, in catch_known_errors return f(*a, **kw) File "<string>", line 2, in make_update_script_for_model File "/Users/johncaine/anaconda/lib/python2.7/site-packages/migrate/versioning/util/__init__.py", line 159, in with_engine return f(*a, **kw) File "/Users/johncaine/anaconda/lib/python2.7/site-packages/migrate/versioning/api.py", line 321, in make_update_script_for_model engine, oldmodel, model, repository, **opts) File "/Users/johncaine/anaconda/lib/python2.7/site-packages/migrate/versioning/script/py.py", line 69, in make_update_script_for_model genmodel.ModelGenerator(diff,engine).genB2AMigration() File "/Users/johncaine/anaconda/lib/python2.7/site-packages/migrate/versioning/genmodel.py", line 197, in genB2AMigration for modelCol, databaseCol, modelDecl, databaseDecl in td.columns_different: ValueError: too many values to unpack
各种google后发现了原因,是在http://stackoverflow.com/questions/20250901/python-sql-alchemy-migrate-valueerror-too-many-values-to-unpack-when-migrat找到的答案,非常感谢stackoverflow的大神,
就是在modle.py中定义数据表的时候使用了Boolean,当我把db.Boolean都换成了db.SmallInteger就解决了问题,非常感谢啊。。。另外,发现在定义的时候Boolean是不分大小写的,所以记得完全更换,就不会影响迁移了,太开心啦~~~
boolean对应的是tinyint,smallinteger对应的是smallint,,,当迁移之后,mysql中的tinyint不会转换为smallint,但是不会影响使用。
使用的sqlalchemy是0.7.9,sqlalchemy-migrate是0.7.2
最后附一个学习sqlalchemy的地址,非常好:http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database
收获不会与付出成反比
by juandx