鲸落海底,哺暗界众生十五年。——加里·斯奈德

如果直接修改GAV版本号

1
2
3
4
5
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.212</version>
</dependency>

你会获得一堆报错

image-20220719125555489

下面是我的ddl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)
);

需要修改为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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

原先的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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');

修改后:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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');

成功运行

image-20220719125843166