Django makemigrations No changes detected in app

2019-07-27 11:51发布

I have trouble with my makemigrations command.

Note: I have successfully make migrations till now, so it is not the first time I try to make migrations on this project.

I have my project in INSTALLED_APPS.

Problem: For some reason project stop detecting any changes in my models.

Inside my project models.py I have:

from myproject.myfolder import myModel1
from myproject.myfolder import myModel2
from myproject.myfolder import myModel3

if a add new models as myModel4 class and import it inside models.py and I try to

python mamange.py makemigrations environment=local

I get No changes detected

I know there are a lot of posts of making the initial migrations, so I even try

python manage.py makemigrations myproject environment=local

I even try to delete all files in __pycache__ but it doesn't work for me.

I even try to delete database and create new one, and it doesn't work either.

EDIT:

Because I delete the database and make it new again, database is empty, but I still get same message.

2条回答
Explosion°爆炸
2楼-- · 2019-07-27 12:22

Deleting the DB and creating new one will never work since it refer the previous migration files. Delete all previous migration files and pycache files except init. Then try running these.

    python manage.py migrate --fake-initial
    python manage.py makemigrations
    python manage.py migrate

This worked for me

查看更多
倾城 Initia
3楼-- · 2019-07-27 12:23

I just ran into an issue like this. In my case, the problem was that I had installed, through pip, the stable version of the package that I was developing, and Django was importing the stable version rather than my development version. To check if this is the case with you, try adding a syntax error to models.py. If makemigrations doesn't trigger the syntax error, then you'll know that your version is not even being loaded by the python interpreter.

查看更多
登录 后发表回答