我正在使用FluentMigrator.dll进行数据库设置,我希望它可以在程序运行任何服务器时创建或更新其数据库。
所以我访问了此页面以解决此问题
Is it possible to use fluent migrator in application_start?
将这些代码输入我的项目;
public static void MigrateToLatest(string connectionString)
{
var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));
var assembly = Assembly.GetExecutingAssembly();
CreateDB(connectionString);
var migrationContext = new RunnerContext(announcer)
{
Namespace = "Mueasyco.MVCWebUI.Migrations.DefaultDB"
};
var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 };
var factory =
new FluentMigrator.Runner.Processors.SqlServer.SqlServer2012ProcessorFactory();
using (var processor = factory.Create(connectionString, announcer, options))
{
var runner = new MigrationRunner(assembly, migrationContext, processor);
runner.MigrateUp();
}
}
您将看到CreateDB()方法,它为我的项目提供了一个数据库。
因此,MigrateUp()不会给出任何错误,但它不起作用
感谢您的回答