如果直接修改GAV
版本号
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.212</version>
</dependency>
你会获得一堆报错
下面是我的ddl
:
drop table if exists user_info;
create table if not exists user_info(
id BIGINT(20) AUTO_INCREMENT NOT NULL COMMENT '主键ID',
name VARCHAR(30) NULL DEFAULT NULL COMMENT '姓名',
age INT(11) NULL DEFAULT NULL COMMENT '年龄',
email VARCHAR(50) NULL DEFAULT NULL COMMENT '邮箱',
PRIMARY KEY (id)
);
drop table if exists user_role;
create table if not exists user_role(
id BIGINT(20) AUTO_INCREMENT NOT NULL COMMENT '主键ID',
user_id BIGINT(20) NULL DEFAULT NULL COMMENT '用户ID',
role_id BIGINT(20) NULL DEFAULT NULL COMMENT '角色ID',
PRIMARY KEY (id)
);
drop table if exists role_info;
create table if not exists role_info(
id BIGINT(20) AUTO_INCREMENT NOT NULL COMMENT '主键ID',
role_name VARCHAR(30) NULL DEFAULT NULL COMMENT '角色名称',
PRIMARY KEY (id)
);
需要修改为:
drop table if exists user_info;
create table if not exists user_info
(
id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL COMMENT '主键ID',
name VARCHAR(30) NULL DEFAULT NULL COMMENT '姓名',
age INT NULL DEFAULT NULL COMMENT '年龄',
email VARCHAR(50) NULL DEFAULT NULL COMMENT '邮箱',
PRIMARY KEY (id)
);
drop table if exists user_role;
create table if not exists user_role
(
id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL COMMENT '主键ID',
user_id BIGINT NULL DEFAULT NULL COMMENT '用户ID',
role_id BIGINT NULL DEFAULT NULL COMMENT '角色ID',
PRIMARY KEY (id)
);
drop table if exists role_info;
create table if not exists role_info
(
id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL COMMENT '主键ID',
role_name VARCHAR(30) NULL DEFAULT NULL COMMENT '角色名称',
PRIMARY KEY (id)
);
然后是初始化数据,自增的话,就不要再传入id
了
原先的:
DELETE
FROM user_info;
INSERT INTO user_info (id, name, age, email)
VALUES (1, 'Jone', 18, 'test1@baomidou.com'),
(2, 'Jack', 18, 'test2@baomidou.com'),
(3, 'Tom', 28, 'test3@baomidou.com'),
(4, 'Sandy', 21, 'test4@baomidou.com'),
(5, 'Billie', 24, 'test5@baomidou.com');
DELETE
FROM user_role;
INSERT INTO user_role (id, user_id, role_id)
VALUES (1, 1, 1),
(2, 1, 2),
(3, 2, 1),
(4, 2, 3),
(5, 3, 1),
(6, 4, 1),
(7, 4, 2),
(8, 5, 1),
(9, 5, 2),
(10, 5, 3);
DELETE
FROM role_info;
INSERT INTO role_info (id, role_name)
VALUES (1, 'admin'),
(2, 'user'),
(3, 'guest');
修改后:
DELETE
FROM user_info;
INSERT INTO user_info (name, age, email)
VALUES ('Jone', 18, 'test1@baomidou.com'),
('Jack', 18, 'test2@baomidou.com'),
('Tom', 28, 'test3@baomidou.com'),
('Sandy', 21, 'test4@baomidou.com'),
('Billie', 24, 'test5@baomidou.com');
DELETE
FROM user_role;
INSERT INTO user_role (user_id, role_id)
VALUES (1, 1),
(1, 2),
(2, 1),
(2, 3),
(3, 1),
(4, 1),
(4, 2),
(5, 1),
(5, 2),
(5, 3);
DELETE
FROM role_info;
INSERT INTO role_info (role_name)
VALUES ('admin'),
('user'),
('guest');
成功运行