(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()

註釋掉的部分應該註釋下面的那句,具體分析有空寫

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