0

I'm following this tutorial.. and the initial auto generate is perfect.. it basically creates the migration file with the upgrade and downgrade methods just fine.

so let's say this is the migration file's revision number: 3e96cf22770b.. all of my upgrade statements look like this:

def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('hashtag',
                    sa.Column('id', sa.VARCHAR(), autoincrement=False, nullable=False),
                    sa.Column('text', sa.VARCHAR(), autoincrement=False, nullable=True),
                    sa.PrimaryKeyConstraint('id', name=u'hashtag_pkey')
                    )

and my downgrade statement looks like this:

def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('user_access_token')

Now I made a simple modification to my models.py file, this is what it looks like on git:

-    verificationCode = Column(String())
+    isVerified = Column(Boolean())

The thing is, I have no idea how to run an autogenerate statement that actually just give me a delta migration file.. ie i just want a migration file that replaces one column by another..

i tried setting the current revision to 3e96cf22770b then running

python migrate.py db revision --autogenerate

but then it keeps on creating duplicates of the initial migration file (ie migrating the entire database schema) rather than just the delta.. ideas?

abbood
  • 23,101
  • 16
  • 132
  • 246

2 Answers2

1

Alembic automatically generates a migration script (using the --autogenerate flag) by observing the current DB schema (it actually connects the DB and fetches the schema) and the new model (in your python code). So when you want to create a new migration script, make sure your database is at the previous schema (3e96cf22770b in your case).

Not sure how you tried to set the current schema, but you can check for the schema at alembic_version table in your DB.

Eran Friedman
  • 578
  • 6
  • 9
0

You should be able to run:

python migrate.py db migrate

and that should create a new migration file for you. Once you get that you can run:

python migrate.py db upgrade 

and that will upgrade your database. Before you upgrade your db, look at the migration file and see if it's doing what you're wanting to do.

juzten
  • 144
  • 1
  • 7
  • that's not my question at all – abbood May 08 '15 at 08:42
  • Well from the docs you linked to, it says the migrate.py db revision --autogenerate creates an empty migration script. From your question it looks like you want to remove the verificationCode column and add an isVerified column to the database table/schema, am I wrong? – juzten May 08 '15 at 12:35