Changes between Initial Version and Version 1 of Ticket #17241
- Timestamp:
- Nov 16, 2011, 6:56:04 PM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #17241 – Description
initial v1 1 1 In a model for my database I am trying to define an Accounts table with the id of a default Django User. 2 2 {{{ 3 #!python 3 4 class Accounts(models.Model): 4 5 user = models.OneToOneField(User) 5 user = models.OneToOneField(User) 6 }}} 6 7 When I have it set up like this and try to add a user in the adduser view: 7 8 9 {{{ 10 #!python 8 11 def adduser(request): 9 username = request.POST['username'] 10 password = request.POST['password'] 11 u = User.objects.create_user(username, request.POST['email'], password) 12 u.save() 13 a = Accounts(user=u) 14 p = Passwords(user=u) 15 a.save() 16 p.save() 17 user = authenticate(username=username, password=password) 18 if user is not None and user.is_active: 19 auth.login(request, user) 20 return HttpResponseRedirect("/%s/" %u.id) 21 else: 22 return HttpResponseRedirect("/account/invalid/") 12 username = request.POST['username'] 13 password = request.POST['password'] 14 u = User.objects.create_user(username, request.POST['email'], password) 15 u.save() 16 a = Accounts(user=u) 17 p = Passwords(user=u) 18 a.save() 19 p.save() 20 user = authenticate(username=username, password=password) 21 if user is not None and user.is_active: 22 auth.login(request, user) 23 return HttpResponseRedirect("/%s/" %u.id) 24 else: 25 return HttpResponseRedirect("/account/invalid/") 26 }}} 27 23 28 There is an integrity error: 24 29 {{{ 25 30 IntegrityError at /adduser 26 31 insert or update on table "XXXX_accounts" violates foreign key constraint "user_id_refs_id_468fbcec324e93d2" 27 32 DETAIL: Key (user_id)=(10) is not present in table "XXXX_user". 33 }}} 28 34 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.