1668A, 14th Main Rd, Sector 7, HSR Layout, Bengaluru, Karnataka 560102
+91 99459 30733 (9am - 6pm IST, Tuesday - Sunday)
Django Model Changes not taking effect
When developing a new feature I created Models and then I had to completely change the model structure. When running makemigrations and migrate Django couldn't make the changes as it was quite significant.
Steps to achieve this:
1. Deleted tables from the database for the new feature that I was creating.
2. Delete migrations file that were newly added. Checking git status can reveal the newly added model files.
3. Then I did makemigrations which created the one migration file with name 0001_initial.py.
4. When running migrate Django says "No migrations to apply"
5. This is because Django checks for entry in django_migrations table and then decides if there are any changes in the model.
6. You can delete the records for the particular feature model changes and migrate should take effect.
7. In case you end up deleting entire django_migrations table. Then to restore run command "python manage.py migrate --fake". This will restore all the records in django_migration table without making any database changes.
8. This will also add model record for the newly added feature model. Simply delete this record and you should be good to run "python manage.py migrate".