Django Models (1054, “Unknown column in 'field list'”)

Viewed 9397

I am struggling with the following Unknown column in field list error. Any help would be really appreciated.

OperationalError at /admin/login/person/
(1054, "Unknown column 'login_person.status_info' in 'field list'")
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/login/person/
Django Version: 1.11
Exception Type: OperationalError
Exception Value:    
(1054, "Unknown column 'login_person.status_info' in 'field list'")
Exception Location: D:\Users\Pubudu\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\connections.py in query, line 292
Python Executable:  D:\Users\Pubudu\AppData\Local\Programs\Python\Python36\python.exe
Python Version: 3.6.1
Python Path:    
['C:\\Users\\Pubudu\\workspace\\village',
 'D:\\Users\\Pubudu\\AppData\\Local\\Programs\\Python\\Python36\\python36.zip',
 'D:\\Users\\Pubudu\\AppData\\Local\\Programs\\Python\\Python36\\DLLs',
 'D:\\Users\\Pubudu\\AppData\\Local\\Programs\\Python\\Python36\\lib',
 'D:\\Users\\Pubudu\\AppData\\Local\\Programs\\Python\\Python36',
 'D:\\Users\\Pubudu\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-packages']
Server time:    Fri, 19 May 2017 15:06:24 +0000

my models.py file :

class Person(models.Model):
    person_id = models.UUIDField(primary_key = True, default=uuid.uuid4)
    #date_created = models.DateField(auto_now_add = True)   
    first_name = models.CharField(max_length = 50)
    last_name = models.CharField(max_length = 100)
    date_of_birth = models.DateField() 
    email = models.EmailField()
    phone_number = PhoneNumberField()   

    address_1 = models.CharField(max_length = 200)
    address_2 = models.CharField(blank=True, max_length = 200)
    city = models.CharField(max_length = 100)

    state = USStateField()

    zipcode = USZipCodeField() 
    country = models.CharField(max_length = 40)
    status_info = models.TextField(blank = True)


    USER_TYPE = (
        ('a', 'Patron'),
        ('b', 'Chef'),
        ('c', 'Driver'),
        )    
    user_type = models.CharField(max_length=6, choices=USER_TYPE, default='a', help_text='User type')

    USER_STATUS = (
        ('a', 'Active'),
        ('b', 'License_approved'),
        ('c', 'Suspended'),
        ('d', 'Pending'),
        ('e', 'Terminated'),       
        ('f', 'Terminated for ever'),       
        )
    person_status = models.CharField(max_length=1, choices=USER_STATUS, default='d', help_text='Registered user status')

    #class Meta:
            #ordering = ["-last_name"] 

    def __str__(self):
        """
        String for representing the Model object.
        """
        return '(%s)' % (str(self.person_id))

admin.py :

    from django.contrib import admin
    from .models import Person
    # Register your models here.

    class PersonAdmin(admin.ModelAdmin):
    list_display = [field.name for field in getattr(Person, '_meta').get_fields()
'_meta').get_field_by_name('location_x')[0].name
                    if not getattr(Person, '_meta').get_field('first_name').name
                    ]
pass

admin.site.register(Person, PersonAdmin)

I am not sure how "login_person.status_info" get into this code. I physically deleted all migration files and ran makemigrations. everything is fine but this causes data entry fails in admin site. what is wrong withthe field status_info ?

1 Answers

It seems you haven't done python manage.py makemigrations then finally python manage.py migrate, ensure that every time you add new column to your model you run migrations so that the changes can be applied to your database and tables.

Related