Django - makemigrations - No changes detected

前端 未结 30 1487
伪装坚强ぢ
伪装坚强ぢ 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:30

    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
      │   └── ...
    

提交回复
热议问题