I was trying to create migrations within an existing app using the makemigrations command but it outputs \"No changes detected\".
Usually I create new apps using the
There are multiple possible reasons for django not detecting what to migrate during the makemigrations
command.
INSTALLED_APPS
.dictmakemigrations -v 3
for verbosity. This might shed some light on the problem.INSTALLED_APPS
it is recommended to specify the full module app config path 'apply.apps.MyAppConfig'manage.py makemigrations --settings mysite.settings
manage.py makemigrations myapp
- that narrows down the migrations for the app alone and helps you isolate the problem. model meta check you have the right app_label
in your model meta
Debug django debug django core script. makemigrations command is pretty much straight forward. Here's how to do it in pycharm. change your script definition accordingly (ex: makemigrations --traceback myapp
)
allow_syncdb
method.makemigrations always creates migrations for model changes, but if allow_migrate() returns False,
In my case i forgot to insert the class arguments
Wrong:
class AccountInformation():
Correct
class AccountInformation(models.Model):
My problem was much simpler than the above answers and probably a far more common reason as long as your project is already set up and working. In one of my applications that had been working for a long time, migrations seemed wonky, so in a hurry, I did the following:
rm -r */migrations/*
rm db.sqlite3
python3 manage.py makemigrations
No changes detected
Whaat??
I had mistakenly also removed all the __init__.py
files :( - Everything was working again after I went in and:
touch ads1/migrations/__init__.py
For each of my applications then the makemigrations
worked again.
It turns out that I had manually created a new application by copying another and forgot to put the __init__.py
in the migrations
folder and that confinved me that everything was wonky - leading my making it worse with an rm -r
as described above.
Hope this helps someone from swearing at the "No changes detected" error for a few hours.
When adding new models to the django api application and running the python manage.py makemigrations
the tool did not detect any new models.
The strange thing was that the old models did got picked by makemigrations
, but this was because they were referenced in the urlpatterns
chain and the tool somehow detected them. So keep an eye on that behavior.
The problem was because the directory structure corresponding to the models package had subpackages and all the __init__.py
files were empty. They must explicitly import all the required classes in each subfolder and in the models __init__.py
for Django to pick them up with the makemigrations
tool.
models
├── __init__.py <--- empty
├── patient
│ ├── __init__.py <--- empty
│ ├── breed.py
│ └── ...
├── timeline
│ ├── __init__.py <-- empty
│ ├── event.py
│ └── ...
I had a different issue while creating a new app called deals
. I wanted to separate the models inside that app so I had 2 model files named deals.py
and dealers.py
.
When running python manage.py makemigrations
I got: No changes detected
.
I went ahead and inside the __init__.py
which lives on the same directory where my model files lived (deals and dealer) I did
from .deals import *
from .dealers import *
And then the makemigrations
command worked.
Turns out that if you are not importing the models anywhere OR your models file name isn't models.py
then the models wont be detected.
Another issue that happened to me is the way I wrote the app in settings.py
:
I had:
apps.deals
It should've been including the root project folder:
cars.apps.deals
To create initial migrations for an app, run makemigrations
and specify the app name. The migrations folder will be created.
./manage.py makemigrations <myapp>
Your app must be included in INSTALLED_APPS
first (inside settings.py).