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?
As @inception said my tables schema had changed & running
syncdbdid not update already created tables.Apparently any changes to the models when updated through
syncdbdoes not change (as in update/modify) the actual tables. So I dropped the relevant DB & ransyncdbon empty DB. Now it works fine. 🙂For others, SOUTH data migration tool for Django seems to be favorite option. It seems to provide options which django models &
syncdbfalls short on. Must check out…Update 29th Sept 2019: From Django 1.7 upwards, migrations are built into the core of Django. If you are running a previous lower version of Django, you can find the repository on BitBucket.