好家伙,又到了修bug的環節,(深嘆一口氣)
好了,來看報錯
2022-10-29 23:27:52.155 WARN 15068 --- [nio-8011-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1364, SQLState: HY000
2022-10-29 23:27:52.156 ERROR 15068 --- [nio-8011-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : Field 'id' doesn't have a default value
2022-10-29 23:27:52.157 ERROR 15068 --- [nio-8011-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement] with root cause
提取關鍵字眼;
Field 'id' doesn't have a default value
去網上查了一圈,
發現是由于"id"屬性沒有勾選"自動遞增"
我們去到資料庫表的設定界面
(我用的MySQL)

說明:勾選①Auto Increment 必須先勾選 ②Prinmary Key否則會報錯
①PRIMARY KEY 約束唯一標識資料庫表中的每條記錄,
主鍵必須包含唯一的值,
主鍵列不能包含 NULL 值,
每個表都應該有一個主鍵,并且每個表只能有一個主鍵,
②Auto-increment 會在新記錄插入表中時生成一個唯一的數字,
正如它名稱,一樣它會自動增加
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/523141.html
標籤:MySQL
