VictorFlower
VictorFlower

Reputation: 1

Delete migeration in django

How do I delete migration In django 1.11 I have tried to delete the particular field in model and make migration again but it's still showing me that I have 3 unapplied migration How do I deal with it ?

Upvotes: 0

Views: 218

Answers (1)

Jazure
Jazure

Reputation: 501

Option 1: Delete newly created migrations and revert to a specific one

  1. Revert the changes in your model/file as you have already done.
  2. Under the "migrations" folder in your app, find the migration that you want to go back to. Run "python manage.py migrate your_app_name name_of_migration_file". This will bring you back to whatever migration you chose.

    Example: if I wanted to go back to the fourth migration, I would do: "python manage.py migrate myapp 0004_auto_20180701_1748". After you have migrated backwards, delete all of the migrations that come after it. For me, I would delete any files 0005 or higher.

  3. Run "python manage.py makemigrations" and then "python manage.py migrate" afterwards.

Option 2: Delete all migrations and reset every single field in your db

This will wipe all of your database data, so I don't recommend doing this every single time. But if you have messed up everything, it is useful because it cleans every single field and migrates all of the ones you currently have in your model file currently.

  1. Make any changes as usual
  2. Delete every file in your "migrations" folder within your app EXCEPT init.py
  3. Run "python manage.py makemigrations" and then "python manage.py migrate" afterwards.

Answer borrowed from here: django revert last migration

Upvotes: 1

Related Questions