首页 > 解决方案 > Django Migration InternalError 1054 未知列

问题描述

我在models.py中的现有项目中添加了一个ImageField,我运行了makeMigrations和Migrate,但是现在如果我转到我的管理面板,我会收到以下错误:

InternalError(1054, u"Unknown column 'activelisting.picture' in 'field list'")

如果我删除该 ImageField,此错误就会消失。

我正在运行 Django==1.11.26

这是该字段的副本:

picture = models.ImageField(null=True, blank=True, upload_to='images/')

非常感谢对此的任何帮助。

编辑:之前应该提到过这一点,但它在 MariaDB 上运行。

管理员.py

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from listings.models import *

from django.contrib import admin

# Register your models here.

def make_active(modeladmin, request, queryset):
        queryset.update(active=True)
make_active.short_description = "Activate selected listings"

def make_inactive(modeladmin, request, queryset):
        queryset.update(active=False)
make_inactive.short_description = "Inactivate selected listings"

class ListingAdmin(admin.ModelAdmin):

        #readonly_fields = ['picture']

        list_display = ('address', 'active', 'number_br', 'number_bath', 'owner', 'city',)

        list_filter = ('active', 'owner',)
        ordering = ('-active','address',)
        actions = [make_active, make_inactive,]

admin.site.register(Activelisting, ListingAdmin)

admin.site.disable_action('delete_selected')

模型.py

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models

# Create your models here.

class Activelisting(models.Model):
        active = models.BooleanField(default=False)
        owner = models.CharField(max_length=60, blank=True, null=True)
        address = models.CharField(max_length=100, blank=True, null=True)
        city = models.CharField(max_length=100, blank=True, null=True)
        house_types = (('house', 'House'), ('apartments', 'Apartments'), ('mobile', 'Mobile home'), ('duplex', 'Duplex'), )
        housing_type = models.CharField(max_length=10, choices=house_types, default='house')
        br_types = ( (1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), )
        bath_types = ( (1, '1'), (2, '2'), (3, '3'), (4, '4') )
        number_br = models.IntegerField(choices=br_types, default=1)
        number_bath = models.IntegerField(choices=bath_types, default=1)
        description = models.TextField(blank=True, null=True)
        #picture = models.ImageField(null=True, blank=True, upload_to='images/')

        class Meta:
                managed = False
                db_table = 'activelisting'

标签: pythondjangodjango-models

解决方案


推荐阅读