Django ModelForm Required ForeignKey not Connecting?

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.

Like what you read? Give xster a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.