syncdb 忽略导入的模型
我有一个项目,结构如下:
project/
__init__.py
db/
models/
__init__.py
article.py
project.py
ontology/
__init__.py
coded.py
它有点大,但这就是想法。 models.__init__.py
包含:
from db.models.article import *
from db.models.project import *
from db.models.ontology.coded import *
运行syncdb时,它会忽略models.__init__.py
中导入的所有模型。没有 ImportError
's,并且当向 __init__.py
添加打印语句时,它会愉快地打印导入模型(在运行syncdb时)。
在 __init__.py
中定义的模型仍然可以工作。
这是为什么?我可以强制syncdb 考虑我导入的模型吗?
编辑:应用程序位于 INSTALLED_APPS 中:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'amcatnavigator.navigator',
'amcatnavigator.db',
)
谢谢!
I have a project, structured like this:
project/
__init__.py
db/
models/
__init__.py
article.py
project.py
ontology/
__init__.py
coded.py
It's a little bit bigger, but that's the idea. models.__init__.py
contains:
from db.models.article import *
from db.models.project import *
from db.models.ontology.coded import *
When running syncdb, it ignores all models imported in models.__init__.py
. There are no ImportError
's, and when adding a print statement to the __init__.py
, it happily prints the import models (while running syncdb).
Models defined in __init__.py
work though.
Why is that? Can I force syncdb to account for my imported models?
Edit: The application is in INSTALLED_APPS:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'amcatnavigator.navigator',
'amcatnavigator.db',
)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要将
app_label = 'db'
添加到模型的 Meta 内部类中。You need to add
app_label = 'db'
to your models' Meta inner classes.根据南方(syncdb)文档: http://south.aeracode.org/docs/tutorial /part1.html 它只会为 settings.py 文件中 INSTALLED_APPS 部分中的模型创建表。如果模型正在使用,但它已更改并且您不想丢失任何数据 - 使用迁移: http://south.aeracode.org/docs/tutorial/part1.html#the-first-migration
更新:据我所知,Django 的设计不会找到其中的模型不同的目录:http://code.djangoproject.com/ticket/14007 你可能想要使用app_label
更新:app_label 文档:http://docs.djangoproject。 com/en/dev/ref/models/options/#app-label
According to South (syncdb) docs: http://south.aeracode.org/docs/tutorial/part1.html It will create tables only for those models that are in INSTALLED_APPS section in settings.py file. If model is being used, but its changed and you don't want to lose any data - use migrations: http://south.aeracode.org/docs/tutorial/part1.html#the-first-migration
UPDATE: As far as i looked Django by design wont find the models within different directories: http://code.djangoproject.com/ticket/14007 you might want to use app_label
UPDATE: app_label docs: http://docs.djangoproject.com/en/dev/ref/models/options/#app-label
您的
db
模块似乎未包含在设置的INSTALLED_APPS
列表中。对于其他变体来说,信息还不够。Looks like your
db
module is not included in theINSTALLED_APPS
list in your settings. It is not enough information for other variants.