1

I'm new to Flask and Flask-Migrate. When running python manage.py db migrate -m "explanation", whatever change I made to models.py gets automatically applied to the database (in this case, adding a column to some table).

I thought changes were only supposed to be applied after running python manage.py db upgrade?

Also, in the above example, the migration file contains two functions: upgrade and downgrade. However, they are both empty... Aren't they supposed to be include the changes I wanted to apply to the database?

I've read the documentation and it seems to contradict what is actually happening. Thanks in advance for the help!

JMS
  • 1,039
  • 4
  • 12
  • 20

1 Answers1

2

It's not how Flask-Migrate works. The migrate command discover and generate schema changes, writing it to a file with the migration description code, with a upgrade and a downgrade functions.

The database is changed with the python manage.py db upgrade command.

I suspect you have something dropping your database and recreating it when you run the migrate command. Something like:

db.drop_all()
db.create_all()

It'll recreate the database, probably before Flask-Migrate is able to analyze the schema.

iurisilvio
  • 4,868
  • 1
  • 30
  • 36
  • I think that was it, thank you for the help. Do you have a good resource you'd recommend, to learn more about the library? I can't find a good tutorial / post about it. It seems like there are a few kinks to SQLAlchemy- e.g., it doesn't detect certain small changes to the type of a column. I'd like to learn how to inspect the upgrade script and edit it as necessary... – JMS May 08 '16 at 20:43
  • 1
    Yes, `Flask-Migrate` is just a small `alembic` wrapper. Read `alembic` docs to understand how it works. http://alembic.readthedocs.io/en/latest/ – iurisilvio May 08 '16 at 20:45