python - Alembic/Flask-migrate doesn't recognise database structure -


i have flask-based application , i'm trying enable migrations able manage database structural changes. database not empty , contains tables , records before started alembic , flask-migrate.

first, tried use alembic stand-alone, pip install alembic , configure , use autogenerate generating diff. works fine output not expected:

info  [alembic.autogenerate.compare] detected removed table u'user'   generating /users/me/documents/project/app/migrations/versions/3de1151ce5de_.py ... done 

so table user present in database (i think it's reserved table in postgresql) , have never removed it. also, have bunch of other tables seem invisible alembic. @ first thought failed configure alembic properly, started on , decided try this nice flask extension miguel grinberg. lot easier setup, result same message.

any ideas doing wrong?

edit: decided add important information on how edited original alembic env.py:

.... import sys,os sys.path.append(os.getcwd()) import app app import db target_metadata = db.metadata  ....  def run_migrations_online():     """run migrations in 'online' mode.      in scenario need create engine     , associate connection context.      """     # models need imported visible when migration runs     app.models import model1, model2, model3, model4, model5  ... 

this changes necessary alembic see declarative base , models before migration starts. after dropping standalone approach followed flask-migrate tutorial , didn't touch files there.

edit: ok, we've got deleted 'user' table explained. still, other models don't appear in scripts. think happens since app started before migration scripts created, sqlalechmy db.create_all() call creates tables , why alembic doesn't see difference in colums vs models. perhaps i'm calling create_all() in wrong place?

edit: yes! it, moved db.create_all() below manager.run() , detects changes now. help!

your database has user table, not represented in of sqlalchemy models. correct?

alembic assume have removed table, since auto-migration script show differences between models defined in application , actual database. alembic has no way know have table in database considered exempt migration scripts.

in case, automatic migration feature great, not supposed "automatic". have review generated scripts , fix errors or inaccuracies before use them.

the way move forward edit migration script correct this. take remove table away. migration scripts meant hand edited, don't afraid that.

the unfortunate problem every time issue new migration table remove show again. don't think alembic has way provide exceptions.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -