Django模型(1054,“未知栏目'字段列表'”)

时间:2017-05-19 15:13:03

标签: django

我在字段列表错误中遇到以下未知列。任何帮助都会非常感激。

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

我的models.py文件:

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)

我不确定" login_person.status_info"进入这段代码。我实际上删除了所有迁移文件并运行了makemigrations。一切都很好,但这导致管理网站中的数据输入失败。字段status_info有什么问题?

1 个答案:

答案 0 :(得分:2)

您似乎还没有完成python manage.py makemigrations,最后python manage.py migrate,确保每次向模型添加新列时都会运行迁移,以便更改可以应用于您的数据库和表。