[Sqlalchemy-tickets] Issue #3589: Timestamp column syntax error in migration (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: Greg S. <iss...@bi...> - 2015-11-18 13:42:19
|
New issue 3589: Timestamp column syntax error in migration https://bitbucket.org/zzzeek/sqlalchemy/issues/3589/timestamp-column-syntax-error-in-migration Greg Selvin: I have a Model class with the database column: date_created = db.Column(db.DateTime, default=datetime.utcnow) this generates the following code in my xxx_migrations.py code: Column('date_created', DateTime, default=ColumnDefault(<function ColumnDefault._maybe_wrap_callable.<locals>.<lambda> at 0x1045b22f0>)) Here is the code I borrowed for my db_migrate.py script: ``` #!python import imp 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)) ``` I'm using SQLAlchemy 1.0.9 and Flask-SQLAlchemy 2.1. I don't think it matters, but I'm using a PostgreSQL 9.4 database. Any idea what I'm doing wrong here? |