Syncdb ignores imported models

I have a project structured as follows:

project/ __init__.py db/ models/ __init__.py article.py project.py ontology/ __init__.py coded.py 

This is a bit more, but this idea. models.__init__.py contains:

 from db.models.article import * from db.models.project import * from db.models.ontology.coded import * 

When syncdb starts, it ignores all models imported into models.__init__.py . There is no ImportError , and when you add a print statement to __init__.py it successfully prints the import models (when syncdb starts).

Models defined in __init__.py work.

Why? Can I get 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!

+1
source share
3 answers

According to the South docs (syncdb): http://south.aeracode.org/docs/tutorial/part1.html It will create tables only for those models that are located in the INSTALLED_APPS section of the settings.py file. If the model is used, but its changes and you do not want to lose any data, use the migrations: http://south.aeracode.org/docs/tutorial/part1.html#the-first-migration

UPDATE: how much I look like Django in design, I can’t find the model in different directories: http://code.djangoproject.com/ticket/14007 you can use app_label

UPDATE: app_label docs: http://docs.djangoproject.com/en/dev/ref/models/options/#app-label

+3
source

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

+4
source

It looks like your db module is not included in the INSTALLED_APPS list in your settings. Not enough information for other options.

0
source

Source: https://habr.com/ru/post/885980/


All Articles