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

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

修改了Article的model后,怎么更新到數(shù)據(jù)庫

第一次建model時(shí),漏了最后的括號(hào):

title?=?models.TextField()

加上后出現(xiàn)錯(cuò)誤:

OperationalError at /admin/blog/article/

no?such?column:?blog_article.title

重新添加括號(hào)后,嘗試????python manage.py makemigrations? 但是出現(xiàn)如下問題:

You are trying to add a non-nullable field 'title' to article without a default; we can't do that (the database needs something to populate existing rows).

Please select a fix:

?1) Provide a one-off default now (will be set on all existing rows with a null value for this column)

?2) Quit, and let me add a default in models.py

此時(shí)選擇1)也沒有解決,應(yīng)該怎么解決?

正在回答

1 回答

解決了:在該修改后模型后,第二次同步數(shù)據(jù)庫時(shí)title字段不能為空。如果第一次就創(chuàng)建title字段,則無影響,因?yàn)樵摫頉]有現(xiàn)有的行。如果數(shù)據(jù)表第一次已經(jīng)創(chuàng)建并且已經(jīng)在表插入數(shù)據(jù),則必須定義一個(gè)默認(rèn)值來填充已有的行, 否則數(shù)據(jù)庫會(huì)因?yàn)檫`反數(shù)據(jù)的完整性而不接受數(shù)據(jù)表更改。

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕粉1426586204

太棒了??!
2019-12-30 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

修改了Article的model后,怎么更新到數(shù)據(jù)庫

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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