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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:29:16+00:00 2026-06-09T17:29:16+00:00

userform class UserForm(forms.ModelForm): confirm_password = forms.CharField(label=Confirm Password,widget=forms.PasswordInput(attrs = {‘placeholder’: ‘Confirm Password’,’class’:’required’})) phone = forms.CharField(max_length

  • 0

userform

class UserForm(forms.ModelForm):
    confirm_password = forms.CharField(label="Confirm Password",widget=forms.PasswordInput(attrs = {'placeholder': 'Confirm Password','class':'required'}))    
    phone =    forms.CharField(max_length = 15,widget = forms.TextInput(attrs = {'placeholder':'Enter mobile no. ','class':'required number'}))
    profession = forms.CharField(max_length= 50,widget = forms.Select(choices = PROFESSION_CHOICES,attrs = {'class':'required'}))

    email = forms.EmailField(label='Email address',max_length = 75,widget = forms.TextInput(attrs={'placeholder':'Enter a valid email.','class':'required email'}))
    sex = forms.CharField(max_length = 20,label="I am :",widget=forms.Select(choices=SEX_CHOICES,attrs = {'class':'required'}))
    password = forms.CharField(label="Password",widget=forms.PasswordInput(attrs = {'placeholder': 'Password','class':'required'})) 
    first_name = forms.CharField(max_length = 50,widget = forms.TextInput(attrs={'placeholder':'Please enter your real name.','class':'required alphabets'}))
    last_name = forms.CharField(max_length = 50,widget = forms.TextInput(attrs={'placeholder':'Enter last name.','class':'required alphabets'}))
    def clean_first_name(self):
        first_name = self.cleaned_data['first_name']
        if first_name == '':
            raise forms.ValidationError("This field is required.")
    def clean_phone(self):
        phone = self.cleaned_data['phone']
        if phone == '':
            raise forms.ValidationError("This field is required.")

    def clean_last_name(self):
        last_name = self.cleaned_data['last_name']
        if last_name == '':
            raise forms.ValidationError("This field is required.")
    def clean_email(self):
        email = self.cleaned_data.get("email")
        try:
            user  = User.objects.get(email = email)
            raise forms.ValidationError("Email already in use.")
        except User.DoesNotExist:
            return email
    def clean_profession(self):
        profession = self.cleaned_data['profession']
        if profession == "":
            raise forms.ValidationError("Select a valid option.")

    def clean_sex(self):
        sex = self.cleaned_data['sex']
        if sex == "":
            raise forms.ValidationError("Select a valid option.")

    def save(self,*args,**kw):
        user = super(UserForm,self).save(*args,**kw)
        user.set_password(self.cleaned_data.get("password"))
        user.first_name = self.cleaned_data.get("first_name")
        user.last_name = self.cleaned_data.get("last_name")
        user.email = self.cleaned_data.get("email")
        user.save()
        user.get_profile().phone = self.cleaned_data.get('phone')
        user.get_profile().location = self.cleaned_data.get('location')
        user.get_profile().profession = self.cleaned_data.get('profession')
        user.get_profile().sex = self.cleaned_data.get('sex')
        return user

    class Meta:
        model = User
        fields = ('username','email','password','confirm_password','first_name','last_name','sex','phone','profession')
        widgets = {
            'password': forms.PasswordInput(),
        }

user registration view

def register_user(request):
    if request.POST:
        data = request.POST.copy()

        data["username"] = 'user'
        rform = UserForm(data)
        #form = UserProfileForm()
        if rform.is_valid():
            try:
                user = rform.save()
                user.username = "user"+str(user.id)
                user.save()
                user = authenticate(username = user.username,password=user.password)
                #register user
                login(request,user)
                return redirect(index)
            except:
                print "Unexpected error"
                raise
        else:
        # submit the same form again.
            form = LoginForm();
            sform = LoginForm()
            return render_to_response('register.html',{'rform':rform,'form':form,'sform':sform},context_instance = RequestContext(request))
    else:
        rform  = UserForm()
        #form = UserProfileForm()
        form = LoginForm()
        sform = LoginForm()
        return render_to_response('register.html',{'rform':rform,'form':form,'sform':sform},context_instance = RequestContext(request))

error

IntegrityError at /accounts/register/
auth_user.first_name may not be NULL

doubt

When i was using the normal user authentication , everything was working perfectly but when i am using it with email authentication , it gives me the above error ,
how do i get past this error , please help , and also how do i make the email field unique as in how do i add index to this field , please help

  • 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-09T17:29:17+00:00Added an answer on June 9, 2026 at 5:29 pm

    Your custom field cleaning methods (clean_*) do not return the cleaned value. From the form validation docs: https://docs.djangoproject.com/en/1.4/ref/forms/validation/

    Just like the
    general field clean() method, above, this method should return the
    cleaned data, regardless of whether it changed anything or not.

    clean_first_name does not have a return which is the same as returning None and the reason why Django is trying to insert a NULL for this field.

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

Sidebar

Related Questions

I have the following code: class UserForm(ModelForm): email = forms.EmailField(widget = forms.TextInput(attrs ={ 'id':'email'}),
from django import forms class UserForm(forms.ModelForm): first_name = forms.TextField(label=_(u'First name'), required=False) last_name = forms.TextField(label=_(u'Last
I'm using a modelform for User like so: class UserForm(forms.ModelForm): class Meta: model =
Hi Here's a snippet from my admin.py #admin.py class UserForm(forms.ModelForm): class Meta: model =
I have a UserForm class which has a select list populated from a related
Hi I am using the django model class with some field and a password
Still fairly new to django and python... I've defined two forms as follows: class
I have an Element Like <div class=control> <label>&nbsp;</label> <input type=checkbox id=1><span class=controlText>Check Box</span> <div
I have a Modelform: class POwner4NewModel(ModelForm): class Meta: model = ProductOwner exclude = (o_owner,o_owner_desc,o_product_model,o_main_image,o_thumbnail,o_gallery_images,o_timestamp,o_status)
I have a userform in 2008 vb express edition. A part number is created

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.