问题描述:
Cause: java.sql.SQLSyntaxErrorException: Key column 'user_name' doesn't exist in table
问题分析:
1、设置主键的字段名称在表格中不存在,导致报错。
CREATE TABLE users(
`username` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名',
`password` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密码',
PRIMARY KEY (`user_name`, `password`) USING BTREE
USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
解决办法:
设置主键的字段名称在表格中存在即可。
CREATE TABLE users(
`username` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名',
`password` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密码',
PRIMARY KEY (`username`, `password`) USING BTREE
USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;