Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DbMigrator - verbose code-first migration

When using Package Manager Console, you can run the following command:

PM> Update-Database -Verbose

The -Verbose switch will write all attempted SQL commands to the console window, which is quite useful for debugging.

You can use the DbMigrator class to do the same in code:

Configuration config = new Configuration();
//... (set up the config object)
DbMigrator migrator = new DbMigrator(config);
migrator.Update();

Is there something like the -Verbose switch if you use the DbMigrator class? I looked all over the documentation, but couldn't find anything.

like image 761
vesan Avatar asked Jun 23 '14 03:06

vesan


People also ask

How do I code my first migration to an existing database?

Run the Add-Migration InitialCreate command in Package Manager Console. This creates a migration to create the existing schema. Comment out all code in the Up method of the newly created migration. This will allow us to 'apply' the migration to the local database without trying to recreate all the tables etc.

What is the difference between automatic migration VS code base migration?

There are those of us that think that "code migration" means "convert code from one language/platform to another" and that "automatic migration" means "do code migration automatically".


1 Answers

See if this article solves your problem:

http://whiteknight.github.io/2013/01/26/efcodeonlymigrations.html

In short:

MigratorScriptingDecorator scripter = new MigratorScriptingDecorator(migrator);
string script = scripter.ScriptUpdate(null, null);
like image 85
Bjørn Furuknap Avatar answered Oct 03 '22 02:10

Bjørn Furuknap