I have a folder with models in which there are several models in files that are already in the database. I just added another file / model, but it is not added to the database when syncdb starts. I tried manage.py validate and it works fine. I also run the code, and it only fails when it tries to save the "table does not exist".
The original structure was like this:
/ models
- __ init __ .py
- file1.py
- file2.py
and __ init __ .py looked like:
from file1 import File1Model from file2 import File2Model
I added file3.py
/ models
- __ init __ .py
- file1.py
- file2.py
- file3.py
and modified by __ init __ .py
from file1 import File1Model from file2 import File2Model from file3 import File3Model
And the contents of the file3 (names can be changed to protect the innocent, but except that it is the exact file):
UPDATE: just tried adding the primary key, since the id field may have been messing around with the automatically added integer primary key identifier. Also tried several options, but did not play dice.
from django.db import models from django.contrib.auth.models import User class File3Model(models.Model): user = models.OneToOneField(User) token = models.CharField(max_length=255, blank=False, null=False) id = models.CharField(primary_key=True, max_length=255) class Admin: pass class Meta: app_label = 'coolabel' def __unicode__(self): return self.user.username @staticmethod def getinstance(user, token, id): try: instance = File3Model.objects.get(pk=id) if instance.token != token: instance.token = token instance.save() return instance except: pass instance = File3Model() instance.user = user instance.token = token instance.id = id instance.save() return instance
So, in this example, File1Model and File2Model are already in the database and remain in the database after syncdb. However, File3Model is not added even after running syncdb again. Is there any way to find out why the new model is not being added?
source share