Question

I have a database shared between django and flask.

In flask app, I use sqlAlchemy and use Alembic to migrate database. But when I migrate database and use command:

$ alembic revision --autogenerate -m "some message"

It will automatically remove all tables that django had created:

INFO  [alembic.migration] Context impl MySQLImpl.
INFO  [alembic.migration] Will assume non-transactional DDL.
INFO  [alembic.autogenerate] Detected removed table u'django_content_type'
INFO  [alembic.autogenerate] Detected removed table u'auth_group'
INFO  [alembic.autogenerate] Detected removed table u'auth_user'
INFO  [alembic.autogenerate] Detected removed table u'auth_user_groups'
INFO  [alembic.autogenerate] Detected removed table u'django_session'
INFO  [alembic.autogenerate] Detected removed table u'auth_permission'
INFO  [alembic.autogenerate] Detected removed table u'auth_user_user_permissions'
INFO  [alembic.autogenerate] Detected removed table u'account_userprofile'
INFO  [alembic.autogenerate] Detected removed table u'south_migrationhistory'
INFO  [alembic.autogenerate] Detected removed table u'django_site'

How to configure Alembic so that database migration does not remove tables of django?

Was it helpful?

Solution

I resolved this problem by my self:

In env file, function:

def run_migrations_online():
    target_metadata.reflect(engine, only=[ "django_content_type", "auth_group", ...])

Put your tables here. This define with engine that the tables were existed and do not drop them.

OTHER TIPS

You can use include_object from the environment context. The function can return True or False, indicating if the given table/object should be considered in the autogenerate sweep

See here for more details: Alembic API

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top