not sure what you are doing wrong but I get the same error using Django 1.2.3 with mysql. Sorry if that is not helpful.
On Sep 28, 6:48 am, Szymon <szy...@mwg.pl> wrote: > Hi, > > Problem: sometimes (not always) get_or_create is trying to create > duplicated record. > > Model: > > class online(models.Model): > postac = models.OneToOneField('postac.postacie', > related_name="lista_online") > data = models.DateTimeField() > > Code snippet: > > o = > online.objects.filter(postac__user=request.user).exclude(postac=request.ses > sion['postac']) > o.delete() > o, c = online.objects.get_or_create(postac=request.session['postac'], > defaults={ 'data' : datetime.now()+timedelta(minutes=15) }) > if not c: > o.data = datetime.now()+timedelta(minutes=15) > o.save() > > Database schema: > > Column | Type | > Modifiers > -----------+-------------------------- > +----------------------------------------------------------------- > id | integer | not null default > nextval('spoleczniak_online_id_seq'::regclass) > postac_id | integer | not null > data | timestamp with time zone | not null > Indexes: > "spoleczniak_online_pkey" PRIMARY KEY, btree (id) > "spoleczniak_online_postac_id_key" UNIQUE, btree (postac_id) > Foreign-key constraints: > "spoleczniak_online_postac_id_fkey" FOREIGN KEY (postac_id) > REFERENCES postac_postacie(id) DEFERRABLE INITIALLY DEFERRED > > PostgreSQL error: > > Sep 28 12:35:42 postgres postgres[7238]: [2-1] ERROR: 23505: > duplicate key value violates unique constraint > "spoleczniak_online_postac_id_key" > Sep 28 12:35:42 postgres postgres[7238]: [2-2] DETAIL: Key > (postac_id)=(109387) already exists. > Sep 28 12:35:42 postgres postgres[7238]: [2-3] LOCATION: > _bt_check_unique, nbtinsert.c:388 > Sep 28 12:35:42 postgres postgres[7238]: [2-4] STATEMENT: INSERT INTO > "spoleczniak_online" ("postac_id", "data") VALUES (109387, > E'2010-09-28 12:50:40.813883') > > Database of course is PostgreSQL, Django 1.2.3 (btw. nice version > number :)), psycopg2 ... what else? So, am I doing something wrong? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.