Mysql报错Duplicate entry '值' for key '字段名'如何解决
遇到这种问题, 是你的数据库表那个字段设置了唯一索引。所以这个字段新增的数据不能重复。具体可以打开表,然后点击表设置

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '测试' for key 'teacher.uk_name' at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.j*a:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.j*a:45) at j*a.lang.reflect.Constructor.newInstance(Constructor.j*a:423) at com.mysql.jdbc.Util.handleNewInstance(Util.j*a:425) at com.mysql.jdbc.Util.getInstance(Util.j*a:408) at com.mysql.jdbc.SQLError.createSQLException(SQLError.j*a:936) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.j*a:3976) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.j*a:3912) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.j*a:2530) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.j*a:2683) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.j*a:2486) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.j*a:1858) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.j*a:1197) at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.j*a:44) at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.j*a) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j*a:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.j*a:43) at j*a.lang.reflect.Method.invoke(Method.j*a:498) at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.j*a:59) at com.sun.proxy.$Proxy118.execute(Unknown Source) at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.j*a:47) at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.j*a:74) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j*a:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.j*a:43) at j*a.lang.reflect.Method.invoke(Method.j*a:498) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.j*a:63) at com.sun.proxy.$Proxy116.update(Unknown Source) at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doUpdate(MybatisSimpleExecutor.j*a:54) at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.j*a:117) at com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.update(MybatisCachingExecutor.j*a:83) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.j*a:197) at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.j*a:184) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j*a:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.j*a:43) at j*a.lang.reflect.Method.invoke(Method.j*a:498) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.j*a:426) ... 61 more
点击表设置查看索引

码上飞
码上飞(CodeFlying) 是一款AI自动化开发平台,通过自然语言描述即可自动生成完整应用程序。
449
查看详情

以上就是Mysql报错Duplicate entry '值' for key '字段名'如何解决的详细内容,更多请关注其它相关文章!
