Django object's id isn't available after save
I have the following Bank
model:
from django.db import models
class Bank(models.Model):
id = models.BigIntegerField(primary_key=True)
name = models.CharField(unique=True, max_length=255)
identi开发者_Go百科fier = models.CharField(unique=True, max_length=255)
created_at = models.DateTimeField()
updated_at = models.DateTimeField()
class Meta:
db_table = u'bank'
app_name = 'mcif'
Now look at this:
>>> from mcif.models import *
>>> b = Bank()
>>> b.name = "wee"
>>> b.identifier = "wee"
>>> b.save()
>>> b.id
>>>
If I understand how Django works, that Bank
object is supposed to get updated with the id of the saved record. Any idea why this isn't happening?
Its a problem in Django when dealing with BigInt as Autoincrementing PK. Maybe this code snippet helps you solve this issue. Its a makeshift solution
精彩评论