Django : ProgrammingError: column “id” does not exist

Whichever database you use as your backend, django needs every table to have a primary key.

If you have specified primary key in your model definition, you will never get this error.

If you have not defined primary key then django automatically creates a column named id (auto increment) and treat this as primary key.

If django takes care of both the situation, why are you getting this error ?

Well, most likely you have not created table using django migrate command. Your table already existed and you want to use this in django,

How to fix this issue ?

Simple, add a primary key to table and update your model to reflect the same.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.