Django ModelForm Required ForeignKey not Connecting?

xster
xster
Published in
1 min readSep 14, 2012

You have a ModelForm based on a Model with a non-optional ForeignKey field. You already connected it via something like

instance = SomeClass(someRelatedObject = someObject)
form = SomeForm(request.POST, instance = instance)

but form.is_valid() is still giving you an error saying someRelatedObject can’t be null. One possible solution is to check your SomeClass’s definition of someRelatedObject. Try putting ‘editable = False’ in your ForeignKey constructor and it may solve your problem.

--

--