django 報錯:ValueError: The database backend does not accept 0 as a value for AutoField.
錯誤原因:
在建立一個model時,其中一個欄位你用了別一個model的做為外來鍵,並且給這個外來鍵設定了一個預設值 ,而這個預設值不適用於鍵model中自動建立
再找一下報錯的指令碼:
Applying oiarpt.0004_auto_20170822_1419... OK
Applying oiarpt.0005_auto_20170822_1652...Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "D:\python3.6\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
由上面的資訊可以看出在執行:Applying oiarpt.0005_auto_20170822_1652…Traceback (most recent call last):時報錯的:
開啟專案\oia_report\oiarpt\migrations 找到對應的檔案可以看到:
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, to='oiarpt.Product'),
問題就出在這裡:
解決方法:
刪除0005_auto_20170822_1652.py
然後重新執行:
python manage.py makemigrations
python manage.py migrate
此時就不會報錯了
相關文章
- Django報錯ValueError: invalid literal for int() with base 10:DjangoError
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions報錯解決辦法Express
- According to TLD or attribute directive in tag file, attribute value does not accept any expressionExpress
- dbfread報錯ValueError錯誤解決方法Error
- streamlit run執行報錯,Invalid value: File does not exist: XXX.py
- 使用JSTL庫的時候: According to TLD or attribute directive in tag file, attribute value does not accept anyJS
- 解決tensorboard報錯ValueError: Duplicate plugins for name projectorORBErrorPluginProject
- minio連線失敗報錯ValueError: path in endpoint is not allowedError
- How does one rename a database?Database
- Qt 報錯 “類名”does not name a typeQT
- Django 報錯 TemplateDoesNotExistDjango
- nginx 報錯 accept4 () failed (24: Too many open files)NginxAI
- Django報錯django.utils.datastructures.MultiValueDictKeyErrorDjangoASTStructError
- Django 報錯資訊總結Django
- ValueError: Length of values (141) does not match length of index (4278)問題的解決ErrorIndex
- vipca報錯 Error 0PCAError
- 網站報錯:“Database Server Error”網站DatabaseServerError
- FAQ:Field DATABASE does not exist; see long textDatabase
- Nginx報錯: "Too many open files accept" 和 "could not build the server_names_hash"NginxUIServer
- Access denied for user 'default'@'%' to database 'shop'報錯Database
- restore database報錯ora-19573RESTDatabase
- Django使用終端建立superuser報錯。Django
- MySQL 5.7啟動資料庫報錯'does not exist or is not executable'MySql資料庫
- ORACLE匯出文字到MYSQL 報錯 Incorrect integer value: ''OracleMySql
- Maven建立SSM專案 啟動時報錯Mapped Statements collection does not contain value for xxxMavenSSMAPPAI
- python: invalid value encountered in divide以及invalid value encountered in double_scalars報錯PythonIDE
- onnx模型轉openvino報錯nGraph does not support the following ONNX operations: If模型
- oracle for linux安裝報錯 file /home/oracle/.Xauthority does not existOracleLinux
- Qt 標頭檔案互相包含會報錯'' does not name a typeQT
- django3整合django-mdeditor報 ‘X-Frame-Options‘ 錯誤Django
- Python中遇到奇怪的錯誤ValueError:badmarshaldataPythonErrorLDA
- value xxx for the flexfield segment customer:does not exist in the value set xxxxFlex
- recover database delete archivelogs skip tablespace temp;報錯DatabasedeleteHive
- Django(21)migrate報錯的解決方案Django
- java.lang.IllegalArgumentException: Mapped Statements collection does not contain value forJavaExceptionAPPAI
- Python執行報錯IndentationError: unindent does not match any outer indentation levelPythonError
- Oracle ORA - 01720 grant option does not exist for..報錯解決Oracle
- job呼叫過程報錯 ORA-00942: table or view does not existView