我正在尝试在我的 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
或将其更改为兼容的应用程序名称(没有".",小写和下划线)。