2

I changed one of the field from IntegerField to ForeignKey. Migrations went well and query is working in mysql but when i start the server and load the homepage i get this error

(1054, "Unknown column 'job_test.suite_id_id' in 'field list'")

where job_test is a table and suite_id is a foreign key referencing to another table.

Please help.

0

1 Answer 1

3

As documented under ForeignKey:

Database Representation

Behind the scenes, Django appends "_id" to the field name to create its database column name. In the above example, the database table for the Car model will have a manufacturer_id column. (You can change this explicitly by specifying db_column) However, your code should never have to deal with the database column name, unless you write custom SQL. You’ll always deal with the field names of your model object.

Therefore you need to rename your field to suite instead of suite_id, or else specify db_column to override the column name Django is trying to use.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.