Django,NOT NULL constraint failed: main_app_staff.course_id
я копирую проект на github, код следующий:
модели:
class CustomUser(AbstractUser):
#some info need to submit
class Course(models.Model):
name = models.CharField(max_length=120)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Staff(models.Model):
course = models.ForeignKey(Course,on_delete=models.DO_NOTHING)
admin = models.OneToOneField(CustomUser,on_delete=models.CASCADE)
def __str__(self):
return self.admin.last_name + " " + self.admin.first_name
'''
views.py:
'''
if request.method == 'POST':
if form.is_valid():
first_name = form.cleaned_data.get('first_name')
last_name = form.cleaned_data.get('last_name')
address = form.cleaned_data.get('address')
email = form.cleaned_data.get('email')
gender = form.cleaned_data.get('gender')
password = form.cleaned_data.get('password')
course = form.cleaned_data.get('course')
passport = request.FILES.get('profile_pic')
fs = FileSystemStorage()
filename = fs.save(passport.name, passport)
passport_url = fs.url(filename)
try:
user = CustomUser.objects.create_user(
email=email,password=password,user_type=2,first_name=first_name,last_name=last_name,profile_pic = passport_url
)
user.gender=gender
user.address=address
user.save()
staff = Staff(course = Course.objects.get(name=course),admin = user)
staff.save()
messages.success(request,"Successfully Added")
return redirect(reverse("add_staff"))
except Exception as e:
messages.error(request, "Could Not Add " + str(e))
else:
messages.error(request, "Please fulfil all requirements")
return render(request,"hod_template/add_staff_template.html",context)
но когда я отлаживаю его, он продолжает сообщать мне "NOT NULL constraint failed: main_app_staff.course_id", я не уверен, нужно ли мне создавать объект Staff
я не знаю как это решить .... пожалуйста