[Django] No changes detected even if make migrations is executed after creating a Model

phenomenon

After creating a new model, even if you execute make migrations, the output will be as follows, and I encountered a phenomenon that the migration file is not created, so make a note of the countermeasure.

#Execute the following command after creating a new model
$ python manage.py makemigrations
No changes detected

Folder structure

app
├─migrations
├─models
│  ├─__init__.py
│  ├─accounts.py
│  └─users.py    #Newly added model this time
└─views
   ├─__init__.py
   └─account.py

Cause

Apparently, if the model is created by dividing it into the models folder, it will not be recognized unless the newly created model is imported into \ __ init__.py.

The contents of the original \ __ init__.py

app/models/__init__.py


from accounts.py import AccountsModel

Add the newly added users.py here.

app/models/__init__.py


from accounts.py import AccountsModel
from users.py import UsersModel #Newly added

Run again

$ python manage.py makemigrations
Migrations for 'app':
  app\migrations\0002_users.py
    - Create model UsersModel

I was able to create it safely!

Recommended Posts

[Django] No changes detected even if make migrations is executed after creating a Model
User is not added successfully after creating a custom User model
Make the model a string on a Django HTML template