Skip to content
Advertisement

Field ‘id’ expected a number but got ‘Free’

i’m trying to add a form, so users can post thier own articles , but when i hit publish button it shwos Field 'id' expected a number but got 'Free'. . i wasn’t adding the package_category field to the forms because i have set a default value for it in my models.py

JavaScript

when i now add the package_category field to the forms.py fields = [...] it now shows this error Field 'id' expected a number but got 'Free'. . i don’t really know what is going

Views.py

JavaScript

Advertisement

Answer

When adding a default for a Foreign Key, you can’t set it to a string like “Free” or “EPS”. You have to point the default to the actual object you are referring to. In your example, you have to point it to an object created by an Package_Category class. The code below is just an example, since I don’t know how your Package_category is structured :

JavaScript

Note that it has to use the method get_or_create since since you won’t have the object available if the model is being run for the first time. Ensure that it gets created automatically to prevent errors.

The error trace is telling you that you have to change the default from “EPS” for file_format field as well.

Advertisement