Opened 13 years ago

Closed 13 years ago

#16587 closed Bug (invalid)

get_or_create duplicate entry with together_unique

Reported by: lazzaroleonardo@… 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:1 by llazzaro, 13 years ago

Sorry this is the right description

model example

class Example(Stat):
    numeric = models.IntegerField(...) 
    date = models.DateField(...)

    class Meta:
       unique_together = ('numeric','date')

If 72 and '2011-08-07' is already stored

Example.object.get_or_create(numeric=72,date='2011-08-07')

raises

django.db.utils.IntegrityError: (1062, "Duplicate entry '72-2011-08-07'
Version 0, edited 13 years ago by llazzaro (next)

comment:2 by Aymeric Augustin, 13 years ago

Does this work?

import datetime
Example.object.get_or_create(numeric=72, date=datetime.date(2011, 8, 7))

comment:3 by llazzaro, 13 years ago

Resolution: invalid
Status: newclosed

the problemas was with auto_now_add=True in DateField

Note: See TracTickets for help on using tickets.
Back to Top