Opened 12 years ago

Last modified 12 years ago

#17241 closed Bug

Postgres Table not updating correctly on save with autocommit on — at Initial Version

Reported by: anonymous Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
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

In a model for my database I am trying to define an Accounts table with the id of a default Django User.

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:

def adduser(request):
username = request.POSTusername
password = request.POSTpassword
u = User.objects.create_user(username, request.POSTemail, 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.

Change History (0)

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