我创建了一个在spring-session-jdbc的spring_session
表上具有外键约束的表。其主要动机是spring-session将删除行,以便其级联并删除与实际会话关联的条目。因为当我启动开发服务器时只有我已经有该表,所以这成为“仅在我的机器上工作”的问题。只有在其他人首先注释掉表,初始化服务器,然后还原并再次进行操作时,此方法才有效。否则,nested exception is java.sql.SQLException: Failed to open the referenced table 'spring_session'
。
我认为解决方案是指定初始化sql文件的运行顺序(或它们之间的依赖关系)。搜索后找不到该设置,所以我在这里。
schema.sql:
drop table if exists foo;
create table if not exists foo (
sid char(36) not null,
foreign key (sid) references spring_session (session_id) on delete cascade,
-- other columns and constraints
);
可能的解决方法:在alter table add constraint
中放入this语句,例如data.sql
。
您可以尝试flyway,它可以通过为它们提供版本号来管理您的初始化sql文件。并且它可以记录已执行的sql,因此,如果添加另一个sql文件,它将执行您添加的sql,并传递已执行的其他sql。