Django: models are not recognized by syncDB or sub after they have been reorganized into separate files

I had a large model file with all classes, etc., and it was difficult to maintain everything in one file. So I reworked this into the model folder, init .py, and placed one on each class.

then i did

manage_noDebug.py schemamigration picviewer --auto manage_noDebug.py schemamigration migrate picviewer 

and south deleted the tables from the database but did not add the model_ * tables as i thought. Can I get him to pick up my model files now?

 manage_noDebug.py sql picviewer 

the conclusion from the foregoing is empty

The structure of my folders:

picviewer / model / INIT .py Picture.py paperType.py ...

one of the file classes:

 class cartItem(models.Model): picture = models.ForeignKey('Picture', null=False) paperType = models.ForeignKey('paperType', null=False) printSize = models.ForeignKey('printSize', null=False) quantity = models.IntegerField(default=1, validators=[validators.MinValueValidator(1)]) price = models.DecimalField(decimal_places=2,max_digits=8) dateCreated = models.DateTimeField(null=False) sessionKey = models.ForeignKey(Session, to_field="session_key", null=False) user = models.ForeignKey(User,null=True) class Meta: app_label = 'picviewer' 

installed applications installed:

 INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.admin', 'picviewer', 'south' ) 

I tried removing the / migrations / directory from the project directory and running syncdb:

 D:\~Sasha\eclipse_workspace\zavalen>manage_noDebug.py syncdb Syncing... No fixtures found. Synced: > django.contrib.auth > django.contrib.contenttypes > django.contrib.sessions > django.contrib.sites > django.contrib.messages > django.contrib.admin > picviewer > south Not synced (use migrations): - (use ./manage.py migrate to migrate these) 

It seems that neither the native syncDB nor the southern schemas see my models.

Here are the tables output from dbShell:

 D:\~Sasha\eclipse_workspace\zavalen>manage_noDebug.py dbshell SQLite version 3.7.5 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> .tables auth_group auth_user_user_permissions auth_group_permissions django_admin_log auth_message django_content_type auth_permission django_session auth_user django_site auth_user_groups south_migrationhistory sqlite> 

Here is the directory for my model:

 D:\~Sasha\eclipse_workspace\zavalen\picviewer\models>dir *.py Directory of D:\~Sasha\eclipse_workspace\zavalen\picviewer\models 15.04.2011 16:38 1 125 cartItem.py 15.04.2011 16:43 1 283 Collection.py 15.04.2011 16:40 419 ImageSizeRatio.py 15.04.2011 16:43 876 Menu.py 15.04.2011 16:43 1 667 Order.py 15.04.2011 14:07 1 457 OrderForm.py 15.04.2011 16:43 490 OrderStatusHistory.py 15.04.2011 16:43 683 paperType.py 15.04.2011 16:43 3 202 Picture.py 15.04.2011 16:43 1 520 printSize.py 15.04.2011 16:43 687 PurchaseItem.py 15.04.2011 16:43 1 239 Tools.py 15.04.2011 16:11 0 __init__.py 
+6
source share
2 answers

To open classes, you need to import them into __init__.py , for example:

 from Picture import Picture from paperType import paperType ... __all__ = ['Picture', 'paperType', ...] 

Import Value important.

If you do not, you do not have access path picviewer.models.Picture , it picviewer.models.Picture.Picture .

+11
source

Perhaps app_label is missing: http://docs.djangoproject.com/en/dev/ref/models/options/#app-label . In addition, syncdb ignores imported models ; it covers most of it. If please add more details so that the answer can be updated.

UPDATE: http://www.djangopro.com/2011/01/django-database-migration-tool-south-explained/ it seems that the models might be fine. Migration can be a problem.

+3
source

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


All Articles