0
如何创建支持方言数据类型的迁移脚本?如何在SQLAlchemy-Migrate中使用方言类型(HSTORE)创建迁移脚本?
这里有一个模型的例子:
db = SQLAlchemy()
class Event(db.Model):
__tablename__ = 'event'
id = db.Column(db.Integer, primary_key=True)
created_at = db.Column(db.DateTime, server_default=text('NOW()'), primary_key=True)
data = db.Column(HSTORE)
这里的错误:
Column('data', HSTORE), NameError: name 'HSTORE' is not defined
附:我用的烧瓶SQLAlchemy的太
迁移脚本:
def migrate(db):
repo, uri = get_config(db)
migration = repo + '/versions/%03d_migration.py' % (
api.db_version(uri, repo) + 1)
tmp_module = imp.new_module('old_model')
old_model = api.create_model(uri, repo)
exec old_model in tmp_module.__dict__
script = api.make_update_script_for_model(uri, repo, tmp_module.meta, db.metadata)
open(migration, "wt").write(script)
api.upgrade(uri, repo)
print 'New migration saved as ' + migration
print 'Current database version: ' + str(api.db_version(uri, repo))
嘣!这是一个男生的错误:)我还使用了一个被破坏的自定义脚本......非常感谢 – DiogoNeves 2014-09-26 14:58:50