- edited description
Timestamp column syntax error in migration
Issue #3589
invalid
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:
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 with psycopg2 2.6.1.
Any idea what I'm doing wrong here?
Comments (3)
-
reporter -
reporter - edited description
-
repo owner - changed status to invalid
this looks like you're reporting against a sqlalchemy-migrate issue? Different project. bugs are at https://bugs.launchpad.net/sqlalchemy-migrate. but it's not a very actively maintained project right now. you might want to look into alembic.
- Log in to comment