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.
class CreateGig(CreateView):
model = Gig
fields = ['title','category','description','price','photo','status']
def form_valid(self, form):
form.instance.user = self.request.user
return super(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"