python - IntegrityError - Column 'user_id' cannot be null -


i trying register new user on site,

class userinfo(models.model):     user = models.foreignkey(user,primary_key=true)#user profile     email_id=models.charfield(max_length=32, null=true, blank=true)    

when registering user, getting stuck integrity error, please me resolve problem.

def registration(request):     registration_dict = {}     if 1==1 :     #if request.post:         #username=request.post['email']         #password=request.post['password']         username="admin@admin.com"         password='123456'         #try:         userinfo.objects.get_or_create(email_id=username,user__username=username,user__email=username,user__password=password)         #except:           #  registration_dict["status"]="0"          #   registration_dict["message"]="username present"            # return httpresponse(simplejson.dumps(registration_dict),content_type="application/json")            registration_dict["status"]="1"         registration_dict["message"]="thank registering"         return httpresponse(simplejson.dumps(registration_dict),content_type="application/json")      else:         registration_dict["status"]="0"         registration_dict["message"]="unable process request"         return httpresponse(simplejson.dumps(registration_dict),content_type="application/json")     

edit 1 have tried changing userinfo.objects.get_or_create(email_id=username,user__username=username,user__email=username,user__password=password,user_id=1) , error changes, to

'cannot add or update child row: foreign key constraint fails (`app_info`.`appdata_userinfo`, constraint `user_id_refs_id_b0fd803b` foreign key (`user_id`) references `auth_user` (`id`))') 

from limited information problem not find userinfo matches. tries create new userinfo, has no user assign user foreignkey. suggest following:

user = authenticate(username=email, password=password) if user none:      user = user(username=email, password=password, email=email) user_info = userinfo.objects.get_or_create(user=user, email_id=email) 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -