Django Models(1054,“Unknown column in”field list“”) [英] Django Models (1054, "Unknown column in 'field list'")

查看:2063
本文介绍了Django Models(1054,“Unknown column in”field list“”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知道为什么会出现此错误。以下是我创建的模型 -

No idea why this error is popping up. Here are the models I created -

from django.db import models
from django.contrib.auth.models import User

class Shows(models.Model):
    showid= models.CharField(max_length=10, unique=True, db_index=True)
    name  = models.CharField(max_length=256, db_index=True)
    aka   = models.CharField(max_length=256, db_index=True)
    score = models.FloatField()

class UserShow(models.Model):
    user  = models.ForeignKey(User)
    show  = models.ForeignKey(Shows)

以下是我访问这些模型的视图 -

Here is the view from which I access these models -

from django.http import HttpResponse
from django.template import Context
from django.template.loader import get_template
from django.http import HttpResponse, Http404
from django.contrib.auth.models import User

def user_page(request, username):
    try:
        user = User.objects.get(username=username)
    except:
        raise Http404('Requested user not found.')

    shows     = user.usershow_set.all()
    template  = get_template('user_page.html')
    variables = Context({
        'username': username,
        'shows'   : shows})
    output = template.render(variables)
    return HttpResponse(output)

此时我收到一个错误 -

At this point I get an error -

OperationalError:(1054,'field list'中的未知列'appname_usershow.show_id')

As你看到这一列甚至不存在于我的模型?为什么这个错误?

As you see this column is not even present in my models? Why this error?

推荐答案

由于@inception表示我的表模式已经改变&运行 syncdb 没有更新已创建的表。

As @inception said my tables schema had changed & running syncdb did not update already created tables.

显然,通过<$ c $更新时,模型的任何更改c> syncdb 不更改(如更新/修改)实际的表。所以我放弃了相关的DB&在空DB上运行 syncdb 。现在工作正常:)

Apparently any changes to the models when updated through syncdb does not change (as in update/modify) the actual tables. So I dropped the relevant DB & ran syncdb on empty DB. Now it works fine. :)

对于其他人, SOUTH 数据迁移工具Django似乎是最受欢迎的选择。它似乎提供了django模型和 syncdb 不足。必须检查...

For others, SOUTH data migration tool for Django seems to be favorite option. It seems to provide options which django models & syncdb falls short on. Must check out...

这篇关于Django Models(1054,“Unknown column in”field list“”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆