0

I am new to django as well as python. I am trying to create a registration and login form.The test registration page works with only the username, email and password. When i try to add firstname, lastname fields for my registration form there was no problem but when i added a new field mobilexnumber, when I go to the admin page, I get the following error

OperationalError at /admin/registration/register/

(1054, "Unknown column 'registration_register.mobilexnumber' in 'field list'")

models.py

class Register(models.Model):
    username = models.CharField(max_length=30)
    email = models.EmailField(max_length=254)
    password = models.CharField(max_length=30)
    firstname = models.CharField(max_length=50)
    lastname = models.CharField(max_length=50)
    mobilexnumber = models.CharField(max_length=50)
    samplefld = models.CharField(max_length=30)

forms.py

class RegForm(forms.ModelForm):

class Meta:
    model = Register
    fields = ('username', 'email', 'password', 'firstname', 'lastname','mobilexnumber', 'samplefld', )
    widgets = {
        'password': forms.PasswordInput(),
    }

Dont mind the samplefld. It was used for some error checking. Even without this field I get the same error.

I am using the following:

Django ver 1.9

Python ver 2.7.11

Pycharm ver 5.0.2

mySQL as database

Thanks!

Savad KP
  • 1,625
  • 3
  • 28
  • 40
user3762146
  • 205
  • 3
  • 13

3 Answers3

0

you should update your mysql db with the new column 'mobilexnumber' (or run syncdb)

alter table register add column `mobilexnumber` varchar(50) NULL;
Eyal Ch
  • 9,552
  • 5
  • 44
  • 54
0

Sounds like you've made changes to your Model without making the corresponding database schema changes. With Django 1.9, run makemigrations and migrate. Here's the documention and you'll see output similar to this:

$ manage.py makemigrations
Migrations for 'register':
  0002_register_mobilexnumber.py:
    - Add field mobilexnumber to register
$ manage.py migrate
Running migrations:
  Rendering model states... DONE
  Applying register.0002_register_mobilexnumber... OK
JCotton
  • 11,650
  • 5
  • 53
  • 59
  • I noticed that the column `mobilexnumber` field does not exist while `samplefld` column exists from mysql command line...Don't know why.... – user3762146 Jan 01 '16 at 02:23
0

After a few searches, I found a somewhat ok solution. I followed all the steps given in this Question. After that as @Eyal suggested I made the raw mySQL query from mySQL command line to add the particular column and it works!

Not the best way, but it works.

Community
  • 1
  • 1
user3762146
  • 205
  • 3
  • 13