迁移成功后未找到表 [英] Table not found after apparently successful migration

查看:94
本文介绍了迁移成功后未找到表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用通过CL的迁移方式来迁移生产数据库(mySql),而我正在使用H2在单元测试中使用固定的SQL查询来创建数据库,表等.我现在想在每次单元测试后更好地集成flyway并创建/删除DB.

I was using flyway through the CL to migrate my production DB (mySql), while I was using a fixed SQL query to create the DB, tables, etc. in my unit tests, using H2. I'd like now to better integrate flyway and create/delete DB after each unit test.

我有一个数据库工厂,并且在其构建方法中,我使用以下代码:

I have a DB factory and inside its build method I'm using the following code:

flyway.setLocations("filesystem:sql/migrations/common","filesystem:sql/migrations/h2");
flyway.setSchemas("MYSERVER");
flyway.setDataSource(
p.getProperty(DB_URL.getName()), 
p.getProperty(USERNAME.getName()), 
p.getProperty(PASSWORD.getName()));
flyway.setInitOnMigrate(true);
flyway.migrate();

迁移似乎正确应用,因为我可以从飞行日志中看到我的SQL代码.但是,当我开始使用DB时,此后立即出现TABLE NOT FOUND错误.我在内存数据库中使用h2,并使用以下URL初始化客户端:

The migrations seems to apply correctly, as I can see my SQL code from the flyway logs. But when I start using the DB, immediately afterwards, I get TABLE NOT FOUND errors. I'm using h2 as in memory DB with the following URL to initialize my client:

jdbc:h2:mem:MYSERVER;MVCC=true

您对我可能做错的事有任何想法吗?

Do you have any idea on what I might be making wrong?

推荐答案

问题是您的JDBC网址.

The problem is your JDBC url.

MYSERVER是数据库的名称,而不是模式.

MYSERVER is the name of the database, not the schema.

最简单的方法是让flyway使用相同的url,而不是设置模式.这样,您将在MYSERVER数据库的公共模式中找到所有内容.

The easiest thing to do is to let flyway use the same url, and not set a schema. This way you'll find everything in the public schema of the MYSERVER database.

这篇关于迁移成功后未找到表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆