Я провожу много часов в поисках такой ошибки, но ничего не нашел,
как вы знаете, Djangov2.00 требует, чтобы вы установили on_delete = *** с ForeignKey, и здесь я больше не могу делать ForeignKey.
мои Models.py
из импортных моделей django.db
class makereport(models.Model):
Name = models.CharField(max_length=50)
VID = models.IntegerField()
Callsign = models.CharField(max_length=6)
Date = models.DateField(default='yy-mm-dd')
SelectAward = models.CharField(max_length=50, choices=(('1', 'Division Online Day'), ('2', 'Pilot Event'), ('3', 'ATC Event'), ('4', 'Pilot Event')))
done = models.ForeignKey('reports', on_delete=models.CASCADE)
# reports.ATC = reports.ATC + 1
def __str__(self):
return self.Name
class reports (models.Model):
Name = models.CharField(max_length=50)
VID = models.IntegerField()
DivisionOnline = models.IntegerField(default=0)
ATCEvent = models.IntegerField(default=0)
PilotEvent = models.IntegerField(default=0)
PilotSupport = models.IntegerField(default=0)
ATC = 0
def __str__(self):
return self.Name
и Ошибка
django.db.utils.IntegrityError: Not Null constraint failed: report_makereport.done_id
Я не знаю, что делать с этим идентификатором, версии до V2 работали.
Views.py
from django.db import IntegrityError
from django.http import HttpResponse, request
from django.shortcuts import render, redirect
# Create your views here.
from django.views import View
from report import models
from report.forms import RepForm
from report.models import makereport, reports
class home(View):
def get(self,request):
form = RepForm()
reps = reports.objects.all()
rep = makereport.objects.all()
context = {
'rep':rep,
'form' : form,
'reps':reps
}
return render(request,'home.html',context)
def post(self,request):
form = RepForm(request.POST)
if form.is_valid():
repo = makereport()
repo.Name = form.cleaned_data['Name']
repo.VID = form.cleaned_data['VID']
repo.Callsign = form.cleaned_data['Callsign']
repo.Date = form.cleaned_data['Date']
repo.SelectAward = form.cleaned_data['SelectAward']
repo.done = None
try:
repo.save()
return redirect('/')
except IntegrityError:
context = {'form':form,
'error_msg': 'Error,Please Check your Information'}
return render(request, 'home.html', context)
else:
return self.get(request)