我正在使用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]
该语句如何找不到上一条语句中创建的表?
答案 0 :(得分:0)
这是可能的原因,
test_schema.person
之类的表时需要提及该模式答案 1 :(得分:0)
仅因为未提及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);