Django中遇到的問題 長期更新

2021-10-06 10:47:01 字數 976 閱讀 6438

本帖用於記錄在學習django的時候遇到的問題以及解決方式

報錯資訊;server returns invalid timezone. go to 'advanced' tab and set 'servertimezone' prope

報錯原因:沒有設定時區

解決辦法:cmd 進入資料庫mysql -hlocalhost -uroot -p輸入密碼進入

接著輸入show variables like'%time_zone';顯示system則代表沒有設定時區

輸入set global time_zone = '+8:00';設定時區,此時原先system處顯示 +08:00

設定成功,重新嘗試連線mysql資料庫

3.使用drf時執行報錯「***:this field is required.」

報錯原因:多半是在serializers中設定了必須

解決辦法:在serializers.***field的引數中新增required=false

age = serializers.integerfield(required=

false

)

或者在extra_kwargs中為該字段新增required=false

extra_kwargs =

}

4.django遷移資料庫遇到specified key was too long; max key length is 767 bytes

可能的報錯原因之一:models裡的某個charfield的max_length超過長度(255)

解決辦法:將超過255長度的charfield的max_length減少為255,或直接改為textfield

Django中遇到的mysql問題

最近在用django寫個 連線mysql的時候出現了幾個問題,總結一下 寫好setting.py和models.py後,syncdb都沒什麼問題,在測試後台發表文章的時候就出錯了,本來是測試markdown的與codelite 高亮,發現發表後debug模式就報錯 error warning inc...

Django初學遇到的問題

1.django.utils.internalerror 1049,unknown database community 在使用mysql資料庫前得先建立資料庫 2.django.core.exceptions.improperlyconfigured error loading mysqldb m...

關於django開發遇到的問題

django框架對於初始使用是可以快速入門的,但是隨著需求的增加其帶來的問題也越來越多。犯了的錯誤以及定位記錄如下 1.資料庫遷移的時候,django admin log,django content type也要進行遷移,不然會導致,migrate失敗。2.如何將echarts嵌入django中 ...