首页 > 解决方案 > Spring Boot gradle flyway - 验证错误 - 模式验证:缺少表

问题描述

我收到以下错误 无法构建 Hibernate SessionFactory;嵌套异常是 org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [my.table]

这是任何版本问题吗?大多数示例甚至官方都不使用模式? https://github.com/spring-projects/spring-boot/tree/main/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-flyway

数据库:MariaDB

步骤:使用创建 V1__init.sql

#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create #spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=V1__init.sql #spring.jpa.properties .javax.persistence.schema-generation.scripts.create-source=元数据

然后添加了flyway插件

flyway.properties 与 build.gradle 处于同一级别

flyway.user=py1***

flyway.password=ENC(aCUoPgiA+ZyHDFdrEXa)

flyway.schemas=我的

flyway.createSchemas=false

flyway.url=jdbc:mariadb://localhost:3306/my

flyway.locations=文件系统:db/migration

应用程序.props

spring.jpa.properties.hibernate.default_schema=my

spring.jpa.hibernate.ddl-auto=验证

将 V1__init.sql 移至 db\migrations

我的实体没有指定架构

@Entity
@Table(uniqueConstraints={
        @UniqueConstraint(....})
    }) 
public class SomeTable {...}

标签: spring-boothibernatejpaflyway

解决方案


添加依赖项 - 实现 'org.flywaydb:flyway-core' 并已解决

(关于 json 类型列的下一个错误 - 找到 [longtext (Types#LONGVARCHAR)],但期望 [json (Types#VARCHAR)] 不在本文讨论范围内)


推荐阅读