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
Deleting migration files means losing your history. This historical info is recorded in the django_migrations table in your database. if you delete migration files, you will get dependency errors. So Don't try to lose your history by deleting your migration files.
Django will remove any prior migrations that were applied to the specified app (myApp). It searches for Python files (migration files) in the migrations folder of each project app, with the exception of init.py, and deletes them.
Django's migration can be reset by cleaning all the migration files except __init__.py files under each project app directory, followed by dropping the database and creating migration again using python manage.py makemigrations and python manage.py migrate .
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.
Just create new directory called migrations inside your app directory.
Then inside that folder create empty folder named __pycache__
and a empty file named __init__.py
. Then just make the migrations and migrate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With