有的时候真的很坑 抄代码都能错
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了有的时候真的很坑 抄代码都能错相关的知识,希望对你有一定的参考价值。
别人用py2 写的教程,我用的是py3,我这尼玛,有多难知道吗..
import imp 过期了..我只能用google去国外找资料..
后来官方查到
1 import imp 2 from migrate.versioning import api 3 from app import db 4 from config import SQLALCHEMY_DATABASE_URI 5 from config import SQLALCHEMY_MIGRATE_REPO 6 migration = SQLALCHEMY_MIGRATE_REPO + ‘/versions/%03d_migration.py‘ % (api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) + 1) 7 tmp_module = imp.new_module(‘old_model‘) 8 old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) 9 exec old_model in tmp_module.__dict__ 10 script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata) 11 open(migration, "wt").write(script) 12 api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) 13 print ‘New migration saved as ‘ + migration 14 print ‘Current database version: ‘ + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)) 15 16 17 ******************py3写法************************* 18 import importlib 19 from migrate.versioning import api 20 from app import db 21 from config import SQLALCHEMY_DATABASE_URI,SQLALCHEMY_MIGRATE_REPO 22 23 migration = SQLALCHEMY_MIGRATE_REPO + ‘/versions/%03d_migration.py‘ % ( 24 api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) + 1) 25 tmp_module = importlib.import_module(‘old_model‘)# 26 old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) 27 exec (old_model in tmp_module.__dict__) 28 script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, 29 db.metadata) 30 open(migration, "wt").write(script) 31 api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) 32 print(‘New migration saved as ‘ + migration) 33 print(‘Current database version: ‘ + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO))) 34 35 就能解决报错..哎.做个啥都不容易.抄都能出错.还得解决..
以上是关于有的时候真的很坑 抄代码都能错的主要内容,如果未能解决你的问题,请参考以下文章
angular11给Echarts添加点击事件,无脑抄代码的时候到了~~ 超好用