Skip to content Skip to sidebar Skip to footer

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): showi

Solution 1:

As @inception said my tables schema had changed & running syncdb did not update already created tables.

Apparently any changes to the models when updated through syncdb does not change (as in update/modify) the actual tables. So I dropped the relevant DB & ran syncdb on 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 & syncdb falls 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.

Solution 2:

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)

Solution 3:

I have met the same problems:

First, run

manage.py sqlall [appname]

and you can find:

`id` integer AUTO_INCREMENT NOTNULLPRIMARY KEY,

and I add the column manual:

ALTERTABLE tb_realtime_data ADD id integer AUTO_INCREMENT NOTNULLPRIMARY KEY FIRST;

and then it worked.

I think django will add the column called id itself.

For convenience, each model is given an autoincrementing primary key field named id unless you explicitly specify primary_key=True on a field (see the section titled “AutoField” in Appendix A).

you can click here for details.

Good luck.

Solution 4:

In the appropriate field explicitly set

primary_key = True

Solution 5:

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.

  1. Manually added column to database through workbench with name exactly the same as it is shown in your error message.

  2. After that run below command

python manage.py makemigrations

Now migrations will be successfully created

  1. After that run below command
python manage.py migrate --fake

Now every thing works fine without any data lose issue

Post a Comment for "Django Models (1054, "unknown Column In 'field List'")"