相关疑难解决方法(0)

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')
Run Code Online (Sandbox Code Playgroud)

)

如果已经存储了72和'2011-08-07'

Example.object.get_or_create(numeric=72,date='2011-08-07')
Run Code Online (Sandbox Code Playgroud)

加薪

django.db.utils.IntegrityError: (1062, "Duplicate entry '72-2011-08-07'
Run Code Online (Sandbox Code Playgroud)

问题是为什么get_or_create提出这IntegrityError就是使用的想法 get_or_create.

不确定这是不是一个bug,我打开了一张票https://code.djangoproject.com/ticket/16587

python django django-models

28
推荐指数
1
解决办法
1万
查看次数

标签 统计

django ×1

django-models ×1

python ×1