1👍
✅
You should first save new_user
instance and then assign it in new student instance.
Relevant code
@login_required(login_url='')
def enroll(request):
if request.method == 'POST':
form = UserForm(request.POST,)
form2 = StudentCreate(request.POST)
if form.is_valid() and form2.is_valid():
new_user = form.save(commit=False)
new_user.save() #form.save() should also work rather than this 2 statements
new_student = form2.save(commit=False)
new_student.user = new_user #assign user instance, not username
new_student.save()
Source:stackexchange.com