[Answered ]-An IntegrityError happened in django1.9

2👍

You are getting this error because the user_id cannot be null:

NOT NULL constraint failed: blogapp_blog.user_id

You also need to add the user:

blog = Blog.objects.create(title=title, content=content,
                           date=timezone.now(), user=request.user)

Please also make sure that only logged-in users are able to access this view by using login_required decorator:

@login_required
def post(request):
    # your stuff here
👤AKS

Leave a comment