MyBatis-plus 提示 Data truncation: Out of range value for column ‘id‘ at row 1

Posted 在奋斗的大道

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MyBatis-plus 提示 Data truncation: Out of range value for column ‘id‘ at row 1相关的知识,希望对你有一定的参考价值。

记录一下MyBatis-plus 提示的错误信息:

### Error updating database.  Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'id' at row 1
### The error may exist in com/zzg/mapper/ScheduleJobMapper.java (best guess)
### The error may involve com.zzg.mapper.ScheduleJobMapper.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO schedule_job  ( id, job_name, cron_expression, bean_name, method_name )  VALUES  ( ?, ?, ?, ?, ? )
### Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'id' at row 1
; Data truncation: Out of range value for column 'id' at row 1; nested exception is com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'id' at row 1] with root cause

com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'id' at row 1

造成上述问题的原因:

可能原因:

1、数据库字段值范围小,插入字段值范围大
        修复:修改数据库字段类型,例如将int改为bigint
2、插入一个临界点的值成功,再次插入则报错
        修复:修改数据库字段类型,例如将int改为bigint
3、使用mybatisplus注解@TableId且没有指定type(或指定为IdType.NONE)
        修复: 指定type=IdType.AUTO

我造成上述原因是主表主键忘记指定增长类型

package com.zzg.entity;

import java.io.Serializable;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import lombok.Data;

@SuppressWarnings("serial")
@TableName(value = "schedule_job")
@Data
public class ScheduleJob implements Serializable {
	@TableId(type = IdType.AUTO)
	private Long id;
	private String jobName;
	private String cronExpression;
	private String beanName;
	private String methodName;
	private Integer status;
	private java.sql.Date createTime;
	private java.sql.Date updateTime;
	private Integer delFlag;
}

 

以上是关于MyBatis-plus 提示 Data truncation: Out of range value for column ‘id‘ at row 1的主要内容,如果未能解决你的问题,请参考以下文章

mybatis-plus使用函数导致执行sql报错问题

Oracle VM Virtualbox打不开开VM ware虚拟机(即vmdk文件)

mybatis-plus invalid bound statement (not found) insert解决办法

27Mybatis-plus整合多数据源

Springboot 整合mongodb 操作工具类仿mybatis-plus风格

Mybatis-plus之QueryWrapperQueryChainWrapperLambdaQueryWrapper以及LambdaQueryChainWrapper用法