Django model foreignkey null=false, but null value on select list on form

  Kiến thức lập trình

I’ve got the following model field:

category = models.ForeignKey(“QuestionCategory”, on_delete=models.CASCADE, null=False, blank=False )

Is it proper behaviour of django, that rendering it in html form, on the select list there are all options (all categories) as well as “empty option”, represented by “———–” ?

(as on the image here):
enter image description here

Still, if selecting that empty option and trying to save, there is validation error, that I need to select one of the element from the list…

New contributor

Andrzej is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

LEAVE A COMMENT