flask 数据库模型修改后的错误修正

类似问题

https://www.cnblogs.com/juandx/p/5278800.html

https://stackoverflow.com/questions/20250901/python-sql-alchemy-migrate-valueerror-too-many-values-to-unpack-when-migrat

修改models.py后运行db_migrate发生错误:

 ./db_migrate.py
/home/hy/.virtualenvs/hy-py3/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py:794: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
  'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
Traceback (most recent call last):
  File "./db_migrate.py", line 19, in <module>
    script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
  File "<decorator-gen-13>", line 2, in make_update_script_for_model
  File "/home/hy/.virtualenvs/hy-py3/lib/python3.5/site-packages/migrate/versioning/util/__init__.py", line 97, in catch_known_errors
    return f(*a, **kw)
  File "<decorator-gen-12>", line 2, in make_update_script_for_model
  File "/home/hy/.virtualenvs/hy-py3/lib/python3.5/site-packages/migrate/versioning/util/__init__.py", line 167, in with_engine
    return f(*a, **kw)
  File "/home/hy/.virtualenvs/hy-py3/lib/python3.5/site-packages/migrate/versioning/api.py", line 321, in make_update_script_for_model
    engine, oldmodel, model, repository, **opts)
  File "/home/hy/.virtualenvs/hy-py3/lib/python3.5/site-packages/migrate/versioning/script/py.py", line 70, in make_update_script_for_model
    genmodel.ModelGenerator(diff,engine).genB2AMigration()
  File "/home/hy/.virtualenvs/hy-py3/lib/python3.5/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 (expected 4)

查网上,有数据类型错,有版本匹配错,真实原因不明,但重新指定版本安装并未解决,简单粗暴:

删除xxx.db数据库文件,然后重新构建

运行db_create.py

再运行db_migrate.py

搞定

猜你喜欢

转载自blog.csdn.net/pocean2012/article/details/86768734
今日推荐