1 回答

TA貢獻(xiàn)1863條經(jīng)驗(yàn) 獲得超2個(gè)贊
實(shí)際上我在 create_user() 方法中有這個(gè)
user_settings = UserSettings(id=user.id, theme='default')
user.save()
user_settings.save()
根據(jù)上面的代碼 user.id 實(shí)際上是 null 。id 在用戶保存到數(shù)據(jù)庫(kù)后被分配。必須將其更改為下面才能使其正常工作
try:
user.save()
except Exception as e:
print(str(e))
raise Exception("Sorry couldn't save the user with email : " + user.email)
if check_user_exists(user.email):
user = get_user_by_email(email=user.email)
user_settings = UserSettings(id_id=user.id, theme='default')
user_settings.save()
else:
raise Exception("Sorry couldn't find the user with email : " + user.email)
添加回答
舉報(bào)