Django 1.7.1 makemigrations 无法识别应用程序
Django 1.7.1 makemigrations does not recognize an application
我有以下 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)
尝试对所有应用程序进行初始迁移会忽略 'user' 应用程序:
> 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'
将 'managed' 用户模型 class 元选项设置为 True 也无济于事。
如何让 Django 识别用户应用程序迁移?
我怀疑你忘记在 user/models/__init__.py
中导入 database
:
from user.models.database import *
我有以下 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)
尝试对所有应用程序进行初始迁移会忽略 'user' 应用程序:
> 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'
将 'managed' 用户模型 class 元选项设置为 True 也无济于事。
如何让 Django 识别用户应用程序迁移?
我怀疑你忘记在 user/models/__init__.py
中导入 database
:
from user.models.database import *