模型例如Django的:get_or_create引发与together_unique
class Example(Stat):
numeric = models.IntegerField(...)
date = models.DateField(auto_now_add=True,...) #auto_now_add=True was the problem
class Meta:
unique_together = ('numeric','date')
)
如果72和 '2011-08-07' 已经存储
Example.object.get_or_create(numeric=72,date='2011-08-07')
引发
django.db.utils.IntegrityError: (1062, "Duplicate entry '72-2011-08-07'
重复条目
问题是为什么get_or_create
引发了IntegrityError
,这就是使用 get_or_create
的想法。
不知道这是一个错误,我打开一票https://code.djangoproject.com/ticket/16587
对不起,如果不清楚的问题。我编辑了这个问题,希望现在好一点 – llazzaro
只是一个普通的'get'与'get_or_create'具有相同的EXACT参数会返回该项目吗? – agf