When trying to update an existing Django model object (with the save()
method), a new row is inserted instead.
For example:
>>> import datetime
>>> from data_lib.models import Meal
>>> m = Meal(name="My First Meal!", description="this is my first meal's description")
>>> print m.mealid
None
>>> m.save()
>>> print m.mealid
None
>>> m.save()
after that second save()
method call, a duplicate entry was inserted into my table.
here is a sample of the model definition:
class Meal(models.Model):
mealid = models.IntegerField(db_column='MealId', primary_key=True)
name = models.CharField(db_column='Name', max_length=45, blank=True)
description = models.CharField(db_column='Description', max_length=200, blank=True)