我有以下Django应用程序结构:
projectname
backend
puzzle
migrations
...
models
database.py
...
user
migrations
...
models
database.py
...
两个应用程序都在项目设置文件中注册:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'backend.puzzle',
'backend.user',
)
puzzle.models.database.py包含一个Django模型:
from django.db import models
class Puzzle(models.Model):
title = models.CharField(max_length=50)
user.models.database.py:
也是如此from django.db import models
class User(models.Model):
name = models.CharField(max_length=50)
尝试在所有应用程序上进行初始迁移会忽略'用户'应用程式:
> python manage.py migrate
Operations to perform:
Apply all migrations: admin, contenttypes, puzzle, auth, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying puzzle.0001_initial... OK
Applying sessions.0001_initial... OK
尝试明确迁移应用程序:
> python manage.py makemigrations user
No changes detected in app 'user'
设置'托管'用户模型类对Meta的元选项也没有帮助。
如何让Django识别用户应用程序迁移?
答案 0 :(得分:1)
我怀疑您忘记在database
中导入user/models/__init__.py
:
from user.models.database import *