Sudip Kafle
Sudip Kafle

Reputation: 4391

Skip a list of migrations in Django

I have migrations 0001_something, 0002_something, 0003_something in a third-party app and all of them are applied to the database by my own app. I simply want to skip these three migrations. One option is to run the following command

python manage.py migrate <third_party_app_name> 0003 --fake

But I don't want to run this command manually. I was thinking if there can be any method by which I can specify something in settings to skip these migrations. I would simply run python manage.py migrate and it would automatically recognize that 3 migrations need to be faked. Or if there is any way to always fake 0001, 0002 and 0003.

If this was in my own app, I could simply remove the migration files but it is a third party app installed via. pip and I don't want to change that.

Upvotes: 4

Views: 2375

Answers (3)

Alasdair
Alasdair

Reputation: 308839

The MIGRATION_MODULES setting lets you specify an alternative module for an app's migrations. You could set this for your app, then leave out the migrations you wish to skip, or replace them with empty migrations.

Upvotes: 2

Sardorbek Imomaliev
Sardorbek Imomaliev

Reputation: 15390

The django knows about applied migrations is only through migration history table. So if there is no record about applied migration it will think that this migration is not applied. Django does not check real db state against migration files.

Upvotes: 1

itzMEonTV
itzMEonTV

Reputation: 20339

If you really want to do that.Try

  • Add entries in django_migrations table like

    app                 name                         applied
    <thirdpartyname>    003_something #without .py   2014-04-16 14:12:30.839899+08 #some date before now
    

Upvotes: 2

Related Questions