错误代码: 1366 Incorrect integer value: 'zhangsan' for column 'depart_teacher' at row 1

1、错误描述

1 queries executed, 0 success, 1 errors, 0 warnings

查询:insert into emp values(6,'胡迪',20,'男')

错误代码: 1366
Incorrect integer value: 'zhangsan' for column 'depart_teacher' at row 1

执行耗时   : 0 sec
传送时间   : 0 sec
总耗时      : 0 sec

2、错误原因

DELIMITER $$

CREATE
    /*[DEFINER = { user | CURRENT_USER }]*/
    TRIGGER `test`.`insert_data` BEFORE INSERT
    ON `test`.`emp`
    FOR EACH ROW BEGIN
	INSERT INTO t_depart_info(id,depart_name,depart_teacher) VALUES(3,'you','zhangsan');
    END$$

DELIMITER ;

INSERT INTO emp VALUES(6,'胡迪',20,'男');

触发器中插入的第三个记录的数据类型是int,但是插入的是varchar类型,导致报错


3、解决办法

(1)将t_depart_info表中的depart_teacher数据类型由int改为varchar

(2)触发器中插入depart_teacher由字符串改为整型

你可能感兴趣的:(错误代码: 1366 Incorrect integer value: 'zhangsan' for column 'depart_teacher' at row 1)