Django的不能makemigrations嵌套的应用

时间:2019-01-31 09:40:25

标签: django django-migrations django-apps

我正在尝试在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)的其他可重用应用程序的负载。

1 个答案:

答案 0 :(得分:1)

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