Calling the following adduser function in views.py. I save the user
first because it's id (automatically created by Django upon INSERT) is
the primary/foreign key for accounts and passwords. Adding a user
seems to be working fine, but then when it gets to the
`Accounts(user=u)`, the following error throws:

    IntegrityError at /adduser
    insert or update on table "OmniCloud_App_accounts" violates
foreign key constraint "user_id_refs_id_468fbcec324e93d2"
    DETAIL:  Key (user_id)=(4) is not present in table
"OmniCloud_App_user".

But the key should be there since it just saved the user to the db...

    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/")

Here is the beginning to the initialization of Accounts:

    from django.db import models
    from django.contrib.auth.models import User
    class Accounts(models.Model):
            user = models.ForeignKey(User)

thanks for any help you all can give, and let me know if you need
anymore code!

-- 
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.

Reply via email to