找不到H2数据库错误:90146.启动时未创建H2数据库 [英] H2 Database not found error: 90146. H2 database is not created on start
问题描述
只需从spring初始化程序创建一个简单的spring-boot项目.我去添加本地h2 db进行测试,但无法登录.似乎它无法在启动时创建测试数据库,但无法弄清楚为什么是这种情况.
Just created a simple spring-boot project from the spring initializer. I went to add a local h2 db for testing and am unable to login. Seems that it cannot create the test db when starting up but cannot figure out why this may be the case.
spring:
h2:
console:
enabled: true
path: /h2
datasource:
url: jdbc:h2:mem:testdb;
username: sa
password:
driver-class-name: org.h2.Driver
platform: h2
jpa:
show-sql: true
hibernate:
ddl-auto: create
properties:
hibernate:
dialect=org:
hibernate:
dialect:
H2Dialect: org.hibernate.dialect.H2Dialect
Database "mem:testdb" not found, and IFEXISTS=true, so we cant auto-create it [90146-199] 90146/90146
推荐答案
我遇到了相同的错误,并且发现它们会有所帮助:
I had the same error and I found these to be helpful:
如下所示将2019之前的版本添加到pom.xml文件中:
Adding a pre-2019 version to the pom.xml file as below:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.193</version>
</dependency>
这可以修复错误,但不是正确的方法.较新版本的H2数据库不会创建新数据库,因为默认情况下不存在该新数据库,并且出于安全目的将其设置为false.
This fixes the error but isn't the right way to do it. The newer version of H2 Database do not create a new database as it doesn't exist by default and are enabled to false for security purposes.
一种更好的方法是添加对url的更改,例如:
A better way would be adding making changes to url as:
jdbc:h2:mem:testdb;IFEXISTS=FALSE;
希望它会有所帮助.我在application.properties
文件中进行了更改.
Hope it helps. I made changes in my application.properties
file.
这篇关于找不到H2数据库错误:90146.启动时未创建H2数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!