(1048, "Column 'user_id' cannot be null")

今天用Django写网站中的注册部分的时候遇到这个问题了,记录下如何改正。
因为我用到了Django自带的用户系统的profile扩展功能,在注册的时候写入数据库需要注意:

user = User.objects.create_user(username, email, password1)
user.save()
#用户扩展信息
# profile = UserProfile()
# profile.yyId = yyid
# profile.yyName = yyname
# profile.mainPlayer = mainplayer
profile = UserProfile(user=user,yyId=yyid,yyName=yyname,mainPlayer=mainplayer)
profile.save()

注释掉的部分应该注释下面的那句,具体分析有空写

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章