﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
17241	Postgres Table not updating correctly on save with autocommit on	anonymous	nobody	"In a model for my database I am trying to define an Accounts table with the id of a default Django User.
{{{
#!python
class Accounts(models.Model):
    user = models.OneToOneField(User)
}}}
When I have it set up like this and try to add a user in the adduser view:

{{{
#!python
def adduser(request):
    username = request.POST['username']
    password = request.POST['password']
    u = User.objects.create_user(username, request.POST['email'], password) 
    u.save()
    a = Accounts(user=u)
    p = Passwords(user=u)
    a.save()
    p.save()
    user = authenticate(username=username, password=password)
    if user is not None and user.is_active:
        auth.login(request, user)
        return HttpResponseRedirect(""/%s/"" %u.id)
    else:
        return HttpResponseRedirect(""/account/invalid/"")
}}}

There is an integrity error:
{{{
IntegrityError at /adduser
insert or update on table ""XXXX_accounts"" violates foreign key constraint   ""user_id_refs_id_468fbcec324e93d2""
DETAIL:  Key (user_id)=(10) is not present in table ""XXXX_user"".
}}}
adducer should be saving the user before creating the Accounts class to corresponds, so it shouldn't have an issue with the id being generated automatically by Django, but apparently Postgres has an issue with ForeignKeys."	Bug	closed	Database layer (models, ORM)	1.2	Normal	invalid			Unreviewed	0	0	0	0	0	0
