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.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". adduser 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. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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.