Django 1.7 - makemigrations not detecting changes
This may happen due to the following reasons:
- You did not add the app in
INSTALLED_APPS
list insettings.py
(You have to add either the app name or the dotted path to the subclass of AppConfig in apps.py in the app folder, depending on the version of django you are using). Refer documentation: INSTALLED_APPS - You don't have
migrations
folder inside those apps. (Solution: just create that folder). - You don't have
__init__.py
file insidemigrations
folder of those apps. (Solution: Just create an empty file with name__init__.py
) - You don't have an
__init__.py
file inside the app folder. (Solution: Just create an empty file with name__init__.py
) - You don't have a
models.py
file in the app - Your Python class (supposed to be a model) in
models.py
doesn't inheritdjango.db.models.Model
- You have some semantic mistake in definition of models in
models.py
Note:
A common mistake is to add migrations
folder in .gitignore
file. When cloned from remote repo, migrations
folder and/or __init__.py
files will be missing in local repo. This causes problem.
Migration files are supposed to be included in the repo. read here. If your team frequently faces migration issues you may consider ignoring migration files as follows:
I suggest to gitignore migration files by adding the following lines to .gitignore
file
*/migrations/*
!*/migrations/__init__.py
Remember, it is not recommended to gitignore migration files as per django documentation
If you're changing over from an existing app you made in django 1.6, then you need to do one pre-step (as I found out) listed in the documentation:
python manage.py makemigrations your_app_label
The documentation does not make it obvious that you need to add the app label to the command, as the first thing it tells you to do is python manage.py makemigrations
which will fail. The initial migration is done when you create your app in version 1.7, but if you came from 1.6 it wouldn't have been carried out. See the 'Adding migration to apps' in the documentation for more details.