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 expressionExpress
- streamlit run執行報錯,Invalid value: File does not exist: XXX.py
- dbfread報錯ValueError錯誤解決方法Error
- Maven建立SSM專案 啟動時報錯Mapped Statements collection does not contain value for xxxMavenSSMAPPAI
- 解決tensorboard報錯ValueError: Duplicate plugins for name projectorORBErrorPluginProject
- minio連線失敗報錯ValueError: path in endpoint is not allowedError
- Qt 報錯 “類名”does not name a typeQT
- Django 報錯 TemplateDoesNotExistDjango
- ValueError: Length of values (141) does not match length of index (4278)問題的解決ErrorIndex
- 網站報錯:“Database Server Error”網站DatabaseServerError
- nginx 報錯 accept4 () failed (24: Too many open files)NginxAI
- Django報錯django.utils.datastructures.MultiValueDictKeyErrorDjangoASTStructError
- Access denied for user 'default'@'%' to database 'shop'報錯Database
- python: invalid value encountered in divide以及invalid value encountered in double_scalars報錯PythonIDE
- 異常錯誤 spring boot框架與Redis整合Unexpected character(‘≣‘ (code 8803 / 0x2263): expected a valid value...報錯Spring Boot框架Redis
- Django 報錯資訊總結Django
- eclipse :報錯 ‘XXXX‘ does not name a type的解決辦法Eclipse
- onnx模型轉openvino報錯nGraph does not support the following ONNX operations: If模型
- wlan0 interface does‘t support scanning
- Flutter開發-iOS報錯Trying to embed a platform view but the PrerollContext does not sFlutteriOSPlatformViewContext
- Django使用終端建立superuser報錯。Django
- VUE前端打包報錯:TypeError: Class extends value undefined is not a constructor or nullVue前端ErrorUndefinedStructNull
- @AllArgsConstructor與@Value共同使用引發的報錯問題Struct
- 【BUG記錄】MySQL插入Emoji表情報錯"Incorrect string value"MySql
- Django(21)migrate報錯的解決方案Django
- Django2.2 報錯:UnicodeDecodeError 解決方法DjangoUnicodeError
- django3整合django-mdeditor報 ‘X-Frame-Options‘ 錯誤Django
- Eclipse裡Tomcat報錯:Document base ……does not exist or is not a readable directory(圖文詳解)...EclipseTomcat
- Hadoop的mapreduce出現問題,報錯The auxService:mapreduce_shuffle does not existHadoopUX
- yum安裝軟體報錯:Invalid configuration value: failovermethod=priority...AI
- 在docker中啟動服務報錯:New main PID 558 does not belong to serviceDockerAI
- spring boot 啟動時報錯The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized orJDBC driverSpring BootServerZedJDBC
- 解決 Incorrect datetime value: '0000-00-00 00:00:00' 報錯
- java.sql.SQLException: The server time zone value ‘Öйú±ê׼ʱ¼ä‘ is unrecognized...報錯解決JavaSQLExceptionServerZed
- Windows更新報錯 0xc1900101 0x30018 解決方案Windows
- Oracle 12c DG備庫啟動報錯standby database requires recoveryOracleDatabaseUI
- QT中error: xxx does not name a type xxx錯誤QTError
- django資料庫同步時報錯“Table 'XXX' already exists”Django資料庫