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

详情如下:

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)
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”类型的问题,试了都不管用,一点点试发现是初始化的默认机制的问题。

SpringBoot+JPA 启动建表错误:CommandAcceptanceException: Error executing DDL

spring.datasource.initialization-mode=always

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

 

SpringBoot+JPA 启动建表错误:CommandAcceptanceException: Error executing DDL

这就是报错的原因。

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

你可能感兴趣的:(SpringBoot+JPA)