Search code examples
djangodatabase-migration

Django deleted migrations directory


In my project directory while I was trying to update my code I have accidentally remove the migrations folder of my app, now that I have modified the models and when I use python manage.py makemigrations I get the following message:

Operations to perform:
    Apply all migrations: app_label
Running migrations:
   No migrations to apply.

I have already run this before migrating python manage.py makemigrations app_label


Solution

  • You could just reset your migrations to before your initial migrate and start over. This doesn't delete data in the database, but rather resets the tracking of your migrations. If all of your databases are already migrated to the same level, then you can start over in your migration tracking.

    There is a StackOverflow question here that already addresses it:

    How to reset migrations in Django 1.7?

    In short,

    ./manage.py migrate --fake <app-name> zero
    

    This resets the tracking to prior to your initial migration.

    And then,

    ./manage.py makemigrations <app-name>
    ./manage.py migrate <app-name>
    

    Which recreates the initial migration and applies it.

    As always, if your data is important, make a backup first.