如何修复“ NOT NULL约束失败”

时间:2019-06-20 08:12:06

标签: python-3.x django-2.1

尝试创建对象“ Vote”时发生

错误 老实说,我根本不了解如何解决。

我想我需要抽出矮人,但是怎么办?

class CreateVote(CreateView):
     model = Vote
     template_name = 'art_detail.html'
     fields = ()

def get_initial(self):
    initial = super().get_initial()
    initial['art_id'] = self.kwargs['slug']
    initial['author_id'] = self.request.user
    return initial

def form_valid(self, form):
    model = form.save(commit=False)
    model.save()
    return HttpResponseRedirect(self.get_success_url())

def get_success_url(self):
    return reverse('art_detail')


Traceback:
        return self.form_valid(form) ...
 ▼ Local vars 
 Variable   Value
 args   ()
 form   < VoteForm bound=True, valid=True, fields=()>
 kwargs {'slug': 'rrcom'}
 request    <WSGIRequest: POST '/poll/arts/rrcom/vote/'>
 self   <coll.views.CreateVote object at 0x0000000004709E48>

我指望您的支持,我还是新来的

0 个答案:

没有答案