Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 532425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:24:12+00:00 2026-05-13T09:24:12+00:00

I have an extended UserProfile model in django: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True)

  • 0

I have an extended UserProfile model in django:

class UserProfile(models.Model):
  user = models.ForeignKey(User, unique=True)
  #other things in that profile

And a signals.py:

from registration.signals import user_registered
from models import UserProfile
from django.contrib.auth.models import User

def createUserProfile(sender, instance, **kwargs):
  profile = users.models.UserProfile()
  profile.setUser(sender)
  profile.save()

user_registered.connect(createUserProfile, sender=User)

I make sure the signal gets registered by having this in my __init__.py:

import signals

So that should create me a new UserProfile for every user that registers, right? But it doesn’t. I always get “UserProfile matching query does not exist” errors when I try to log in, which means that the database entry isn’t there.

I should say that I use django-registration, which provides the user_registered signal.

The structure of the important apps for this is, that I have one application called “users”, there I have: models.py, signals.py, urls.py and views.py (and some other things which shouldn’t matter here). The UserProfile class is defined in models.py.

Update: I changed the signals.py to:

from django.db.models.signals import post_save
from models import UserProfile
from django.contrib.auth.models import User

def create_profile(sender, **kw):
    user = kw["instance"]
    if kw["created"]:
        profile = UserProfile()
        profile.user = user
        profile.save()

post_save.connect(create_profile, sender=User)

But now I get a “IntegrityError”:

“column user_id is not unique”

Edit 2:

I found it. Looks like somehow I registred the signal twice. The workaround for this is described here: http://code.djangoproject.com/wiki/Signals#Helppost_saveseemstobeemittedtwiceforeachsave

I had to add a dispatch_uid, now my signals.py looks like this and is working:

from django.db.models.signals import post_save
from django.contrib.auth.models import User
from models import UserProfile
from django.db import models

def create_profile(sender, **kw):
    user = kw["instance"]
    if kw["created"]:
        profile = UserProfile(user=user)
        profile.save()

post_save.connect(create_profile, sender=User, dispatch_uid="users-profilecreation-signal")
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:24:12+00:00Added an answer on May 13, 2026 at 9:24 am

    You can implement it using post_save on the user:

    from django.db.models.signals import post_save
    from models import UserProfile
    from django.contrib.auth.models import User
    
    def create_profile(sender, **kwargs):
        user = kwargs["instance"]
        if kwargs["created"]:
            profile = users.models.UserProfile()
            profile.setUser(sender)
            profile.save()
    
    post_save.connect(create_profile, sender=User)
    

    Edit:
    Another possible solution, which is tested and works (I’m using it on my site):

    from django.db import models
    from django.contrib.auth.models import User
    from django.db.models.signals import post_save
    def create_profile(sender, **kwargs):
        user = kwargs["instance"]
        if kwargs["created"]:
            up = UserProfile(user=user, stuff=1, thing=2)
            up.save()
    post_save.connect(create_profile, sender=User)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have extended Django's User Model using a custom user profile called UserExtension .
In my application I have an extended User model called UserProfile. This user can
I've extended the standard Django User model with a UserProfile, and created a OneToOne
I have two models: UserProfile (extended from user) and Cv . I created another
I extended the User model in Django by using Profiles. As you know, creating
I have extended a class that is part of a large library. I instantiate
I have an Entity class that I have extended using the partial class syntax
I have extended django User with my custom fields , now i need to
I have extended the ASP.NET MVC Html Helper to include my own ValidationImage that
I have extended a server control (not a user control) and put the code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.