In Django , Is it possible to migrate any perticular specific file?

Viewed 1339

Currently I am learning django and learning migration related stuff.

I have found that we can migrate specific app using python manage.py migrate app-name but not found how to migrate specific migration file named python manage.py migrate 0024_auto_20200827_0706.py.

If I will do python manage.py migrate 0024_auto_20200827_0706.py, it will revert migration from this point or file but not doing migrate for this specific file.

My question : is it possible to do migrate for specific file if yes then How is it possible?

Thanks.

1 Answers

No, it is not possible to directly run a single migration out of sequence.

If the migration is a data migration of some sort that could otherwise be run out of sequence (i.e. it doesn't depend on schema changes, or is dangerous to run), I would recommend refactoring it into

  • a "migration utility" function in e.g. myapp/migration_utils
  • the migration itself that just calls the above function
  • a management command that calls the above function

Then you can call the management command manually should you need to, but the migration would be run in-sequence otherwise.

Related