Django query - create record will not return ID -
i experiencing weird behavior , not sure why, able without issue in view.
here's issue: creating , saving new record database, after save not give me id new record null, though record being inserted db without error.
my code:
r = ksprojectrewards() r.project_id = project_id r.reward_description_short = desc_short r.reward_description_long = desc_long r.limit_max = limit r.international_info = international r.is_active = active r.save() r.id # <!-- returns null
here model
class ksprojectrewards(models.model): id = models.integerfield(primary_key=true) project_id = models.integerfield() reward_description_short = models.charfield(max_length=75l, blank=true) reward_description_long = models.charfield(max_length=500l, blank=true) num_backers = models.integerfield(null=true, blank=true) limit_count = models.integerfield(null=true, blank=true) limit_max = models.integerfield(null=true, blank=true) limit_met = models.integerfield(null=true, blank=true) delivery_date = models.datetimefield(null=true, blank=true) international_info = models.charfield(max_length=200l, blank=true) date_added = models.datetimefield() date_updated = models.datetimefield(null=true, blank=true) is_active = models.integerfield() class meta: db_table = 'ks_project_rewards'
you try remove following line model:
id = models.integerfield(primary_key=true)
django takes care auto incremented field.
Comments
Post a Comment