我试图跟随this tutorial设置一个简单的 spring 启动应用程序与postgres . 他们使用Docker来设置db和liquibase . 我之前使用过spring-data和JPA,但没有使用postgres或liquibase .
我试图 Build 一个简单的学生数据库 . 这是我的实体:
@Entity
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@NotNull
private String firstName;
@NotNull
private String lastName;
public Student(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
}
这是liquibase的更改日志
create table "student" (
id bigserial not null,
firstName varchar(50) not null,
lastName varchar(50) not null,
primary key (id)
);
我通过实现CommandLineRunner的类加载一些学生,只是为了获得一些初始数据
启动时,我收到以下错误:
引起:org.postgresql.util.PSQLException:错误:关系“student”的列“first_name”不存在
什么是将firstName列更改为first_name?我可以在Student实体中使用@Column(“first_name”),但那时似乎与变更集中的表定义不一致 .
我不知道为什么liquibase需要表定义,JPA就在那里 . 只要让JPA从@Entity创建表,我认为没有它就更容易了 .
更大的图片是我正在尝试为后端的postgres和前端的ReactJS快速启动应用程序做一个概念验证/脚手架 . This tutorial可能会更好,如果我可以得到postgres后端想通 . 唐't really need docker, but I thought that would make it easier. But now that and liquibase seem to be creating a problem by persisting a db and table that don'匹配 .