Django does assign but not store primary key value
NickName:tannerli Ask DateTime:2013-03-15T18:50:03

Django does assign but not store primary key value

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

More about “Django does assign but not store primary key value” related questions

Django does assign but not store primary key value

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 clas...

Show Detail

Django save integer not null primary key value

I am using django to develop my application. A landmark model class has integer not null primary key field (gid). I want to insert max(gid) + 1 value to that field but can't set it as auto incre...

Show Detail

Change primary key value of an object store

How can I change the primary key value (keyPath) of an object store? If this is not possible, does IndexedDB team have any plans to support this feature?

Show Detail

Primary key and unique key in django

I had a custom primary key that need to be set up on a particular data in a model. This was not enough, as an attempt to insert a duplicate number succeeded. So now when i replace primary_key=Tru...

Show Detail

How does Django handle the incrementation of the AutoField Primary Key?

In a Django project with postgresql, I once inserted en entry in the db, and one day. Someone else who has access to it, has manually added 36 other rows in the db with pgadmin4. When I want to add...

Show Detail

Setting primary key start value in Django model

I am preparing a model as follows: class SomeModel(models.Model): id = models.BigIntegerField(primary_key=True, null=False, unique=True) But my primary key must be a valid 9+ digit integer va...

Show Detail

Django - remove primary_key=True from an existing model?

I have a table that I've already migrated into the MySQL database and one of the fields has primary_key = True. I realized this needs to be different and I need to remove the primary_key = True. I'...

Show Detail

Changing primary key in Django caused constraint does not exist error

I have Django project with DigestIssue model among others and there were Django auto created primary key field id and my field number. I wanted to get rid of duplication and set number as PK because

Show Detail

Renaming Django primary key

I am trying to rename the primary key field of a Django model, but I get django.db.utils.ProgrammingError: column &quot;new_name&quot; of relation &quot;my_app_mymodel&quot; does not exist. The mod...

Show Detail

Django Custom primary key

When I inspect the Trac database I get: class TicketChange(models.Model): ticket = models.IntegerField() time = models.BigIntegerField() author = models.TextField(blank=True) field =

Show Detail