Django Models (1054, “Unknown column in 'field list'”)

后端 未结 13 1737
庸人自扰
庸人自扰 2020-12-08 13:18

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(m         


        
13条回答
  •  孤城傲影
    2020-12-08 13:49

    Normally I get this when when I'm trying to access field which doesn't exist in Database.

    Check if the field exist in the database. If you change model and perform syncdb it won't update the database, I'm not sure if that's the case.

    On other note Django offers shortcut to replace try/except block in your code using get_object_or_404. (available in django.shortcuts )

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

    can be changed to:

    user = get_object_or_404(User, username=username)
    

提交回复
热议问题