Below is what i have tried to add a phone number column in user model:-
from django.contrib.auth.models import AbstractUser
# models.py
# Import the basic Django ORM models library
from django.db import models
from django.utils.translation import ugettext_lazy as _
# Subclass AbstractUser
class User(AbstractUser):
phonenumber = models.CharField(max_length=15)
def __unicode__(self):
return self.username
# forms.py
from django import forms
from .models import User
from django.contrib.auth import get_user_model
class UserForm(forms.Form):
class Meta:
# Set this form to use the User model.
model = get_user_model
# Constrain the UserForm to just these fields.
fields = ("first_name", "last_name", "password1", "password2", "phonenumber")
def save(self, user):
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
user.password1 = self.cleaned_data['password1']
user.password2 = self.cleaned_data['password2']
user.phonenumber = self.cleaned_data['phonenumber']
user.save()
# settings.py
AUTH_USER_MODEL = "users.User"
ACCOUNT_SIGNUP_FORM_CLASS = 'users.forms.UserForm'
But on this change, it raises the OperationalError: (1054, "Unknown column 'users_user.phonenumber' in 'field list'")
I already uses syncdb and migrate options but nothing will work, As i am very new to django, please help me
I am using:- Python2.7, Django 1.6, django-allauth 0.15.0
ModelForm
?Meta
doesn't do anything in a regular form. Anyway, the full traceback will help here. – knbk