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
In the appropriate field explicitly set
primary_key = True
I received this error while trying to use Django Rest Framework serializers. Make sure if you have a serializer that subclasses ModelSerializer
, that you migrate any changes to the Models before writing your serializer classes (or just comment anything related to the serializer, migrate, then uncomment).
I faced the same error like you posted above with MySQL database back-end, after long time of resolving this error, I ended up with below solution.
Manually added column to database through workbench with name exactly the same as it is shown in your error message.
After that run below command
python manage.py makemigrations
Now migrations will be successfully created
python manage.py migrate --fake
Now every thing works fine without any data lose issue
I created a model file for my app and then did several sqlall
as I refined my tables. One of the changes I made was I set primary_key=True
to one of my fields. At the end called for syncdb
. Added a dummy value and and tried to access it with User.objects.all()
, User
being my model class. Although this worked fine, this error came up while printing the list returned by the all()
call. It read DatabaseError: (1054, "Unknown column 'polls_user.id' in 'field list'")
Surprisingly, I tried and could get it resolved with another call to syncdb
. I remember not having seen the id column in the table at any time throughout the exercise when I checked it through the mysql command line client.
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!!
This is quite an old question but you might find the below useful anyway:
Check the database, you're most likely missing the show_id
in the appname_usershow
table.
This could occur when you change or add a field but you forget running migration.
OR
When you're accessing a non managed table and you're trying to add a ForeignKey
to your model.
Following the example above:
class UserShow(models.Model):
# some attributes ...
show = models.ForeignKey(Show, models.DO_NOTHING)
class Meta:
managed = False
db_table = 'appname_departments'