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 8997055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:50:13+00:00 2026-06-15T23:50:13+00:00

I am trying to register users using the Django UserProfile capability. I have an

  • 0

I am trying to register users using the Django UserProfile capability. I have an Extended UserProfile model. My files look like below. I am getting “accounts_userprofile.u_id may not be NULL’, i tried using ‘commit=false’ when saving the form, but it didn’t work. My parent model has the fields set to null= True, blank = True. I have dropped the table and added it a couple of times, but nothing worked. Please help. Thanks in advance

My Models are below:

class UserBase(models.Model):
class Meta:
    abstract = True
    u_id = models.IntegerField(null = True,blank = True)
    email = models.CharField(max_length=200, null = True,blank = True)
    website=models.CharField(max_length=200, null = True, blank = True)
    age = models.IntegerField(blank = True, null = True)
    location = models.CharField(max_length= 200, null=True, blank = True)
    username = models.CharField(max_length = 100, null = True, blank = True)

The UserProfile Model is as follows:

class UserProfile(UserBase):
user = models.ForeignKey(User, null= True, blank = True, unique = True)

User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0]) 
def __unicode__(self):
    return "User Profile for: " + self.user.username

def create_user_profile(sender, **kw):
user = kw[‘instance’]
if kw[‘created’]:
up = UserProfile(user=user)

    up.save()

post_save.connect(create_user_profile, sender = User, dispatch_uid =”user_create_profile”)

My registration View is below:

def register(request, template_name=”registration/register.html”):
if request.method == ‘POST’:

  postdata = request.POST.copy()
  form = UserCreationForm(postdata)
  if form.is_valid(): 

      un = postdata.get('username','')
      pw = postdata.get('password1','')

      from django.contrib.auth import login, authenticate

      new_user = authenticate(username=un, password=pw)
      form.save()
      #if new_user and new_user.is_active:
          #login(request, new_user)
          #url = urlresolvers.reverse('my_account')
          #return HttpResponseRedirect(url)

else:
form = UserCreationForm()
page_title = ‘User Registration’
return render_to_response(template_name, locals(),
context_instance=RequestContext(request))>

  • 1 1 Answer
  • 0 Views
  • 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-06-15T23:50:13+00:00Added an answer on June 15, 2026 at 11:50 pm

    From Django Docs:

    https://docs.djangoproject.com/en/1.4/ref/models/fields/

    Field.unique

    If True, this field must be unique throughout the table.

    This is enforced at the database level and by model validation. If you
    try to save a model with a duplicate value in a unique field, a
    django.db.IntegrityError will be raised by the model’s save() method.

    This option is valid on all field types except ManyToManyField and
    FileField.

    You are telling UserProfiles that the UserProfiles.u_id is unique, it’s not (blanks/null). So you’re getting the error. You may want to consider changing u_id to be a AutoField primary_key. And then connect them using models.ForeignKey(‘UserBase’)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I'm a newbie trying to use django to register some users, I have
When I'm trying to create an extended user profile I'm getting UserProfile object is
I have a problem that I would like to solve using Django's ORM. I
I'm trying to extend the User model in Django using inheritance. Here's my model:
I'm trying to get django-haystack (using a xapian backend) to index my model here
I'm trying to allow new users to register for my Wordpress site using their
I'm trying to allow users to register on my web application via Facebook. As
I'm trying to write a script for users to register to a club, and
I am trying to register the following class using the fluent interface: public class
I'm trying to register my castor mapping files with spring and I appear to

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.