DbMigrator.GetPendingMigrations()始终为空 [英] DbMigrator.GetPendingMigrations() always empty

查看:588
本文介绍了DbMigrator.GetPendingMigrations()始终为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 DbMigrator 类来获取挂起的迁移列表。由于某些原因,即使有待处理的迁移,它也不会返回任何项目。我错过了一步吗?

I'm using the DbMigrator class to get a list of pending migrations. For some reason it returns no items even though there are pending migrations. Am i missing a step?

var configuration = new Migrations.Configuration();
configuration.TargetDatabase = new DbConnectionInfo("MyDatabase");

var migrator = new DbMigrator(configuration);
var migs = migrator.GetPendingMigrations().ToList();
Console.WriteLine(migrator.GetPendingMigrations().ToString());

我以为可能是连接字符串,但有趣的是 migrator。 GetDatabaseMigrations()返回已应用于db的正确迁移列表。

I thought it might be the connection string but what's interesting is that migrator.GetDatabaseMigrations() returns the correct list of migrations already applied to the db.

推荐答案

对我来说,原因是我正在不同的大会工作。在这种情况下,您需要指定包含迁移的程序集和命名空间:

The same happened to me and the reason was that I was working in a different assembly. In that case, you need to specify the assembly and namespace that contains your migrations:

config.MigrationsAssembly = Assembly.GetAssembly(typeof([One of your migration classes]));
config.MigrationsNamespace = "[Namespace containing your migrations]";

这篇关于DbMigrator.GetPendingMigrations()始终为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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