3

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.

Klaus D.
  • 13,874
  • 5
  • 41
  • 48
Moon
  • 4,014
  • 3
  • 30
  • 66
  • 1
    Does this answer your question? [Django 1.8 Run a specific migration](https://stackoverflow.com/questions/32531350/django-1-8-run-a-specific-migration) – Karthik Aug 31 '20 at 06:45
  • What is your use-case for this? Typically running a single migration out of a stack will bring your code and database into an inconsistent state. (If it works at all.) – Klaus D. Aug 31 '20 at 06:52
  • Actually I do not have use-case but just out of curiosity. – Moon Aug 31 '20 at 06:56
  • @Karthik If I will do --fake for previous migrations like 0022,0023 so what about next migrations like starting with 0025,0026 etc. – Moon Aug 31 '20 at 06:58

1 Answers1

1

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.

AKX
  • 152,115
  • 15
  • 115
  • 172
  • 2
    I am not able to understand it properly. It would be great if you can explain me in detail. – Moon Aug 31 '20 at 11:39