save
当我调用该方法时,我的实例似乎被保存了。问题:该实例已存在于我的数据库中!
我的模型:
class DosIdModel(models.Model):
dosId = models.IntegerField(max_length=7, primary_key=True)
proposOrigine = models.CharField(max_length=4)
proposAnnee = models.IntegerField(max_length=4)
proposChrono = models.CharField(max_length=7)
splitNumber = models.IntegerField(max_length=1, blank=True, null=True, default=None)
我的观点:
instance = DosIdModel()
instance.dosId=int(row[0])
instance.proposOrigine=row[1].strip()
instance.proposAnnee=int(row[2])
instance.proposChrono=row[3].strip()
instance.splitNumber=emptyOrVar(row[4], "int")
msg=(instance.dosId)
savedList=[]
errors_list=[]
try:
print "exist: ", DosIdModel.objects.get(dosId=instance.dosId).dosId
instance.save()
print "saved"
savedList.append(msg)
print "end try"
except IntegrityError, e:
print "except"
error= "The row " + str(msg) + " already exists!!"
控制台中的结果:
exist: 104486
saved
end try
怎么了?