Django Help: Resolving Not Null Constraint Failed Error With Createview
I am new to stackoverflow, python and Django, have a question on the '(NOT NULL constraint failed: sixerrapp_gig.user_id)' error I am getting when i click submit on the form. Pret
Solution 1:
You need to handle that in form_valid()
method of the view.
classCreateGig(CreateView):
model = Gig
fields = ['title','category','description','price','photo','status']
defform_valid(self, form):
form.instance.user = self.request.user
returnsuper(CreateGig, self).form_valid(form)
More reference at https://docs.djangoproject.com/en/1.9/topics/class-based-views/generic-editing/#models-and-request-user
Post a Comment for "Django Help: Resolving Not Null Constraint Failed Error With Createview"