Django - makemigrations - No changes detected

前端 未结 30 1585
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 04:44

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

30条回答
  •  难免孤独
    2020-12-02 05:28

    There are multiple possible reasons for django not detecting what to migrate during the makemigrations command.

    1. migration folder You need a migrations package in your app.
    2. INSTALLED_APPS You need your app to be specified in the INSTALLED_APPS .dict
    3. Verbosity start by running makemigrations -v 3 for verbosity. This might shed some light on the problem.
    4. Full path In INSTALLED_APPS it is recommended to specify the full module app config path 'apply.apps.MyAppConfig'
    5. --settings you might want to make sure the correct settings file is set: manage.py makemigrations --settings mysite.settings
    6. specify app name explicitly put the app name in manage.py makemigrations myapp - that narrows down the migrations for the app alone and helps you isolate the problem.
    7. model meta check you have the right app_label in your model meta

    8. 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)

    Multiple databases:

    • Db Router when working with django db router, the router class (your custom router class) needs to implement the allow_syncdb method.

    makemigrations always creates migrations for model changes, but if allow_migrate() returns False,

提交回复
热议问题