【发布时间】:2020-08-29 04:37:28
【问题描述】:
我遇到了一个奇怪的问题。
我的 springboot 应用程序中有一个 schema.sql 文件,它创建表(带有外键约束)并在应用程序运行时插入数据。但这里的问题是,当连接空闲时,连接被测试。现在,这给我带来了问题,因为schema.sql 文件再次执行,并且您知道我的表包含外键约束,因此脚本失败,因为它不允许删除包含外键约束的表。
是因为我的application.properties吗?
这是我的 application.properties
spring.datasource.url=jdbc:mysql://dummy_url
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.initialization-mode=always
mybatis.config-location=classpath:/config/mybatis-config.xml
有没有办法让 schema.sql 只执行一次(仅在应用程序运行时)?
我的示例schema.sql 看起来像这样:
DROP TABLE IF EXISTS `t001_map_mst`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `t001_map_mst` (
`MAP_ID` int NOT NULL AUTO_INCREMENT,
`MAP_NAME` varchar(45) DEFAULT NULL,
PRIMARY KEY (`MAP_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='Contains map info';
/*!40101 SET character_set_client = @saved_cs_client */;
【问题讨论】:
标签: java mysql spring-boot schema mybatis