Django makemigrations No changes detected in app

佐手、 提交于 2019-12-11 05:31:57

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/46789185/django-makemigrations-no-changes-detected-in-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!