成功创建后未找到Spring H2创建的表

我正在使用Spring Boot的schema.sql魔术来创建内存H2数据库。该脚本包含以下语句:

create table PERSON
(
    ID BIGINT not null primary key,NAME VARCHAR(255) not null
);

create index IDX_PERSON_NAME on PERSON (NAME);

启动时,Spring Boo失败,但出现以下异常:

Caused by: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #2 of URL [file:/D:/git/.../build/resources/main/schema.sql]: create index IDX_PERSON_NAME on PERSON (NAME); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "PERSON" not found; SQL statement:
create index IDX_PERSON_NAME on PERSON (NAME) [42102-200]

该语句如何找不到上一条语句中创建的表?

qqwainier1 回答:成功创建后未找到Spring H2创建的表

这是可能的原因,

  1. 在引用诸如test_schema.person之类的表时需要提及该模式
  2. 您用于创建索引的语法可能是错误的。请参考此链接以获取H2语法https://www.baeldung.com/spring-yaml
,

仅因为未提及NAME作为Unique约束,所以您仅将其指定为NOT NULL约束

create table PERSON
(
    ID BIGINT not null primary key,NAME VARCHAR(255) not null,CONSTRAINT Person_Name_Unique UNIQUE (NAME)

);


create index IDX_PERSON_NAME on PERSON (NAME);
本文链接:https://www.f2er.com/3118309.html

大家都在问