Django 无法为嵌套应用程序进行迁移

Django cannot makemigrations for a nested app

我试图在我的 django 项目中创建一个嵌套应用程序,但 makemigrations 没有检测到它。我有以下目录结构:

myproject/
├── db.sqlite3
├── manage.py
├── myproject
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── parentapp
    ├── admin.py
    ├── apps.py
    ├── childapp
    │   ├── admin.py
    │   ├── apps.py
    │   ├── __init__.py
    │   ├── migrations
    │   │   └── __init__.py
    │   ├── models.py
    │   ├── tests.py
    │   └── views.py
    ├── __init__.py
    ├── migrations
    │   └── __init__.py
    ├── models.py
    ├── tests.py
    └── views.py

这里是一些相关代码:

myproject/myproject/settings.py:

INSTALLED_APPS = [
    ...
    'parentapp',
    'parentapp.childapp',
]

myproject/parentapp/childapp/__init__.py:

default_app_config = "parentapp.childapp.apps.ChildAppConfig"

myproject/parentapp/childapp/apps.py:

from django.apps import AppConfig

class ChildAppConfig(AppConfig):
    name = 'parentapp.childapp'

myproject/parentapp/childapp/models.py:

from django.db import models

class Child(models.Model):

    class Meta:
        app_label = "parentapp.childapp"

    name = models.CharField(max_length=100)

我在尝试进行迁移时看到以下行为:

$ myproject/manage.py makemigrations
No changes detected

$ myproject/manage.py makemigrations childapp
No changes detected in app 'childapp'

$ myproject/manage.py makemigrations parentapp.childapp
'parentapp.childapp' is not a valid app label.  Did you mean 'childapp'?

我做错了什么?我看到许多其他具有嵌套应用程序的可重用应用程序(例如 django-allauth)。

您需要从 Child.Meta 中删除 app_label 或将其更改为兼容的应用程序名称(没有“.”、小写和下划线)。