Skip to content Skip to sidebar Skip to footer

Django Migrations Not Detecting All Changes

I have the following models. BaseClass1 and BaseClass2 are abstract models used by models. In this case, the model AdBreak is used by a viewset and a serializer. When I run pytho

Solution 1:

I solved it in multiple ways.

Solution 1

There is a serializer AdBreakSerializer which serializes the model AdBreak. Import AdBreakStatus model into the AdBreakSerializer file. Now AdBreakStatus model is detected and migrated.

Problem in this approach is that, the import is not used, and hence will not follow the standards.

Solution 2

Write the AdBreakStatus model class inside the same file of AdBreak. This will also solve the problem.


Finding / Understanding

The makemigrations script looks for models which are connected from urls.py. The script navigates from urls.py to all the viewset, then the corresponding serializers and models.

All the models which needs to be migrated should come in the path of this traversal. OR Only those models which are traversed in this manner will be migrated.

Solution 2:

In case someone does the same mistake as me, in my case it was because the field I added had the same name as an existing property. So make sure that the field name is not already used.

Solution 3:

Do this first:

python manage.py makemigrations 'your-app'
python manage.py migrate

If the above fails to detect changes, remove migration folder, open your database and open table django_migrations. You will see migrations listed associated to your app, delete the records and now execute makemigrations and migrate.

Solution 4:

delete the migrations folder and sqlite file. then run

python manage.py makemigrations 'app_name'
python manage.py migrate

Post a Comment for "Django Migrations Not Detecting All Changes"