我正在使用 Spring Boot 和 hibernate 开发一个应用程序,它连接到在 docker 中运行的 postgres 实例。当我第一次创建 myschema.sql时,它看起来像这样:
CREATE TABLE groups(
group_id varchar(255) PRIMARY KEY,
group_desc varchar(255),
group_name varchar(255)
);
表创建成功,但是我很快意识到 255 对我的目的来说太短了,并将我的架构更改为以下内容:
CREATE TABLE groups(
group_id text PRIMARY KEY,
group_desc text,
group_name text
);
但是,数据库会不断恢复到原始数据类型。我试过删除表,但是当 Spring 应用程序运行并再次创建它varchar(255)而不是text. 如何强制休眠使用更新的架构?
我尝试将spring.jpa.hibernate.ddl-auto属性更改为createand update,并尝试将字段更改为其他数据类型,包括其他长度的varchar. 到目前为止没有任何效果。即使删除schema.sql看似没有效果。
我的application.properties样子是这样的:
spring.jpa.database=POSTGRESQL
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=<redacted>
spring.datasource.password=<redacted>
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true