syncdb ignores imported models

2019-08-01 04:33发布

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!

3条回答
相关推荐>>
2楼-- · 2019-08-01 05:07

You need to add app_label = 'db' to your models' Meta inner classes.

查看更多
男人必须洒脱
3楼-- · 2019-08-01 05:15

Looks like your db module is not included in the INSTALLED_APPS list in your settings. It is not enough information for other variants.

查看更多
我想做一个坏孩纸
4楼-- · 2019-08-01 05:24

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

查看更多
登录 后发表回答