mysql报错:java.sql.SQLException: Field 'id' doesn't have a default value

mysql报错:java.sql.SQLException: Field ‘id’ doesn’t have a default value

数据库增加数据报错:java.sql.SQLException: Field ‘id’ doesn’t have a default value
原因是表的id属性没有设置自动递增。

java.sql.SQLException: Field 'id' doesn't have a default value
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3978)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3914)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2495)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1903)
	at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2124)
	at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2058)

在设计表的时候,id作为主键勾选自动递增即可解决此问题。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_28023365/article/details/86521965
今日推荐