我是靠谱客的博主 不安猎豹,这篇文章主要介绍SpringBoot+JPA 启动建表错误:CommandAcceptanceException: Error executing DDL"alter table X drop foreign key,现在分享给大家,希望可以做个参考。

搭个Springboot+Jpa环境,一启动就报错:

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table X drop foreign key “FK7x41955roke6bti1oqnvs893h" via JDBC Statement

和:

nested exception is java.lang.IllegalArgumentException: 'script' must not be null or empty

详情如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table X drop foreign key FK7x41955roke6bti1oqnvs893h" via JDBC Statement at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:375) at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:359) at org.hibernate.tool.schema.internal.SchemaDropperImpl.applyConstraintDropping(SchemaDropperImpl.java:331) at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:230) at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:154) at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:126) at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:112) at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:144) at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
org.springframework.jdbc.datasource.init.UncategorizedScriptException: Failed to execute database script from resource [URL [file:/C:/Users/admin/IdeaProjects/ActivitiTest/target/classes/data-mysql.sql]]; nested exception is java.lang.IllegalArgumentException: 'script' must not be null or empty at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:530) at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.populate(ResourceDatabasePopulator.java:240) at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:48) at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.runScripts(DataSourceInitializer.java:210) at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.initSchema(DataSourceInitializer.java:123) at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker.onApplicationEvent(DataSourceInitializerInvoker.java:93) at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker.onApplicationEvent(DataSourceInitializerInvoker.java:37) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) at org.springframework.context.support.AbstractApplicationContext.registerListeners(AbstractApplicationContext.java:826)

在网上找帖子,要不说是方言的问题,要不说是”ddl-auto”类型的问题,试了都不管用,一点点试发现是初始化的默认机制的问题。

复制代码
1
spring.datasource.initialization-mode=always

mode=always时,代表全部数据初始化,包括数据库和内存数据,而这时在classpath里的data-mysql.sql内的数据会自动录入数据库,而我把它注掉了

 

这就是报错的原因。

解决办法:取消屏蔽或者干脆删掉这个文件也可以

最后

以上就是不安猎豹最近收集整理的关于SpringBoot+JPA 启动建表错误:CommandAcceptanceException: Error executing DDL"alter table X drop foreign key的全部内容,更多相关SpringBoot+JPA内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(131)

评论列表共有 0 条评论

立即
投稿
返回
顶部