5

Django -OperationalError: (1054, & ldquo; unknown column 'registration_regis...

 3 years ago
source link: https://www.codesd.com/item/django-operationalerror-1054-unknown-column-registration-register-mobilexnumber-in-field-list.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Django -OperationalError: (1054, & ldquo; unknown column 'registration_register.mobilexnumber' in 'field list' & rdquo;)

advertisements

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!


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

alter table register add column `mobilexnumber` varchar(50) NULL;


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK