Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
699 views
in Technique[技术] by (71.8m points)

python - 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, "Unknown column 'appname_usershow.show_id' in 'field list'")

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

maybe your tables schema has been changed? Also, running syncdb does not update already created tables.

You might need to drop all the tables & then run syncdb again. Also remember to take backup of your data!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...