I have a simple django model
class Directory(models.Model):
id = models.AutoField(primary_key=True)
path = models.TextField(unique=True)
def __unicode__(self):
return self.path
class Meta:
db_table = u'directories'
However, there seems to be some problem to save a Directory instance into the db
>>> from cygapp.models import Directory
>>> d = Directory()
>>> d.path = '/usr'
>>> d.id
>>> d.save()
>>> d.id
4
>>> d
<Directory: /usr>
while the ID field is assigned correctly (the next free value), it is not stored in the db
sqlite> select * from directories;
1|/bin
2|/system/lib
3|/system/bin
|/usr
What am i missing here?
Copyright Notice:Content Author:「tannerli」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15430444/django-does-assign-but-not-store-primary-key-value