NOT NULL constraint failed: Adm_profile.user_id in django Allauth [closed]

1

I have a problem which I have been looking for a solution for a while and I have not been able to find it, since the error that I get, can be solved by putting it in the field of "OneToOneField (null = True), but when doing that my system loses a super important functionality, the function of relating the user that is being created in "Django.auth.User" with the custom fields that I have created, and when you register you jump the following error.

Adm_profile.user_id is the field in the database that must contain the "Id" of the user registered in "auth_user" so that the User data created by means of "Auth" matches those of my custom form, but I get an error, when saving the data, if I put in the field of OneToOneField null = True, the error is removed, but it does not let me save the user_id so that they match both tables :( As I mentioned, I searched a lot and did not I find a solution: (.

Models.py

from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.db import models

# Create your models here.
class Profile(models.Model):
   user = models.OneToOneField(User, on_delete=models.CASCADE)
   first_name = models.CharField(max_length=100)
   last_name = models.CharField(max_length=100)
   Matricula = models.CharField(max_length=25)

forms.py

 from django import forms
 from django.forms import ModelForm
 from models import *
 from django.db import models

 #create your forms here


class SignupForm(forms.ModelForm):
   class Meta:
       model = Profile
       fields = ('first_name', 'last_name', 'Matricula')

      #Saving user data
   def signup(self, request, user):
       user.first_name = self.cleaned_data['first_name']
       user.last_name = self.cleaned_data['last_name']
       user.Matricula = self.cleaned_data['Matricula']
       user.save()

       ##Save profile

       profile = Profile()
       Profile.user = user
       profile.Matricula = self.cleaned_data['Matricula']
       profile.save()

In my settings.py add this line to add the custom fields in the form that comes in Allauth

ACCOUNT_SIGNUP_FORM_CLASS = 'Adm.forms.SignupForm'

As you can see, the user_id that was created in the auth_user table does not save me and so I can not access the attributes that user has.

Please, if someone can help me, I am a student and it is my final project, I have researched a lot, reading the documentation, tutorials in English, but it has not worked for me. Python is a wonderful language < 3

If you need additional information, just tell me, I'm still learning Django, it's something new for me

    
asked by Miguel Toledano 23.09.2016 в 06:27
source

0 answers