syncdb ignores imported models
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!
You need to add app_label = 'db'
to your models' Meta inner classes.
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
Looks like your db
module is not included in the INSTALLED_APPS
list in your settings. It is not enough information for other variants.
精彩评论