django常見錯誤

2022-09-19 05:42:13 字數 1479 閱讀 7188

1.報錯:

could not parse the remainder: ' or ''' from 'next or '''

原因: 一般是template即html****了錯,例如我的,如圖:

這份原本是我flask的前端**,我複製來django的忘了修改,django不支援在}**現單引號。

解決辦法:對應刪除或修改

原因:

1). 可能是你的model與views函式重名了;

2). 缺少必要引數,可以試執行命令列丟擲的錯誤找到缺少的引數,如request;

解決辦法:從model和view的名字和引數下手。

3.報錯:u"unknown column 'myblog_articlemodel.article_id' in 'where clause'"

原因:字段發生了變化。

解決:執行python manage.py makemigrations

4.報錯:provide a one-off default now (will be set on all existing rows with a null

原因:有欄位屬性發生變化,增加了非空字段。

解決:最乾脆就是將migrations下除init.py的所有檔案刪除,重新生成

5.報錯:django.db.utils.internalerror: (1049, u"unknown database 'myblog'")

原因:有的時候如果你在刪除了這個資料庫後,再執行migrate就不管用了,就會報這個錯。

解決:自己在mysql手動建立乙個該資料庫。

命令:create database db_name character set utf8;,其中db_name為資料庫名。

6.報錯:(1054, u"unknown column 'myblog_articlemodel.article_id' in 'where clause'")

原因:該字段不存在,這個錯誤大多出現在id欄位上。

解決:

1. 參考:這個鏈結時,我看到說需要手動在資料庫中建立乙個id鍵。但這個鏈結還沒來得及試驗。因為第2種方法:

2. 因為我已經將資料庫刪了,重新手動建了乙個資料庫(參考錯誤5)。

我碰到的原因是:該字段我用了uuid,**如下:

article_id = models.uuidfield(primary_key=true,default=uuid.uuid4)

執行migrate之後在migrations檔案中也的確生成了這個鍵,然而在mysql中查詢的時候發現這個鍵的鍵名竟然是uid。起初我以為這個鍵比較特別,只能取這個,因為我參考的大多數據用的也是這個,但是後來參考到以上鏈結,覺得不對。於是就用了方法二。

django常見錯誤

1.報錯 could not parse the remainder or from next or 原因 一般是template即html 中出了錯,例如我的,如圖 這份原本是我flask的前端 我複製來django的忘了修改,django不支援在 中出現單引號。解決辦法 對應刪除或修改 原因 1...

Django常見錯誤型別

1.django.core.exceptions.improperlyconfigured requested setting default index tablespace,but settings are not configured.you must either define the en...

django 常見錯誤彙總

file d python django mysite mysite view.py line 7syntaxerror unicode error utf 8 codec can t decode byte 0xa3 in position 0 invalid start byte 1 synta...