Opened 13 years ago
Closed 13 years ago
#16587 closed Bug (invalid)
get_or_create duplicate entry with together_unique
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
model example
class Example(Stat):
numeric = models.IntegerField(...)
date = models.DateField(...)
class Meta:
unique_together = ('name','date')
If 'john' and '2011-6-8' is already stored
Example.object.get_or_create(name='john',date='2011-6-8')
raises django.db.utils.IntegrityError: (1062, "Duplicate entry '72-2011-08-07'
Change History (3)
comment:2 by , 13 years ago
Does this work?
import datetime Example.object.get_or_create(numeric=72, date=datetime.date(2011, 8, 7))
comment:3 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
the problemas was with auto_now_add=True in DateField
Note:
See TracTickets
for help on using tickets.
Sorry this is the right description
model example
Suppose 72 and '2011-08-07' is already stored
this code :
Raises