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

后端 未结 13 1644
庸人自扰
庸人自扰 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:59

    This is a late response but hopefully someone will find this useful.

    I was working on Django REST APIs using DB models. When I added a new column to my existing model(said column already existed in the db table from the start), I received the error shown below: "Unknown column ',column name>' in 'field list'"executed".

    What I missed was migrating the model over to the database.

    So I executed the following commands from python terminal:

    1. py -3 manage.py makemigrations ---> It will not allow NULL values for the new column added to the model, even though the column is present in the database from the start. So you need to add a default value, mine was an Integerfield, so I updated my column definition in the model as IntegerField(default=0). From here onwards it should be straightforward, if there are no other errors.

    2. py -3 manage.py migrate

    3. py -3 manage.py runserver

    After executing these steps when I called my REST APIs they were working properly.

    0 讨论(0)
提交回复
热议问题