第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Django postgress 給出 psycopg2.errors.

Django postgress 給出 psycopg2.errors.

慕后森 2023-12-05 15:00:50
下面是我的模型Windows 10,postgress 12,django 3.0.7,python 3.7.6class User(AbstractBaseUser, PermissionsMixin):    email = models.CharField(max_length=30)    password = models.CharField(max_length=4000)    first_name = models.CharField(default='', max_length=15)    last_name = models.CharField(default='', max_length=15)    login = models.CharField(max_length=15)    age = models.IntegerField()    street = models.CharField(blank=True, max_length=255)    city = models.CharField(blank=True, max_length=255)    zip = models.CharField(blank=True, max_length=10)    role = models.CharField(default='', max_length=10)    USERNAME_FIELD = 'email'當(dāng)我發(fā)出發(fā)布請(qǐng)求時(shí),出現(xiàn)以下錯(cuò)誤File "C:\Users\Akila\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 86, in _execute    return self.cursor.execute(sql, params)psycopg2.errors.NotNullViolation: null value in column "id_id" violates not-null constraintDETAIL:  Failing row contains (null, default).這是被調(diào)用的我的注冊(cè)視圖。@靜態(tài)方法@api_view(['POST'])def sign_up(request):    logging.debug("Trying to register a new user")    data = common_methods.get_request_data(request)    print(data)    if check_user_exists(data['email']):        return JsonResponse({'message': 'User with this email already exists'},status=status.HTTP_400_BAD_REQUEST)    print(data['email'])    create_user(data['email'], data['password'], data['fullName'])    refresh = CustomTokenObtainPairSerializer.get_token(        get_user_by_email(email=data['email']))    return JsonResponse({'token': {        'access_token': str(refresh.access_token),        'expires_in': str(refresh.access_token.lifetime.seconds),        'refresh_token': str(refresh)    }})
查看完整描述

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)


查看完整回答
反對(duì) 回復(fù) 2023-12-05
  • 1 回答
  • 0 關(guān)注
  • 188 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)