Up/down migration of C# Code-First?

c# code-first ef-migrations entity-framework

Question

I started generating the migrations for my model using the add-migration command in the package management console. What about the up-and-down method? I take it that the down method's aim is to eliminate any dependencies and discard any tables that are already present in the database? Moreover, the up technique will be carried out before the down way? The other approach is to create/update tables/indices, etc.

When I do this, does the down approach sometimes generate a lot of tables that are later dropped? Many tables were recently created and dropped, and the up approach experienced much the same situation. Why?

1
44
3/19/2012 11:54:26 AM

Accepted Answer

The Up technique transforms your database's state—as represented by your earlier migration—into the state that is anticipated by your current code migration. TheDown The procedure performs the opposite action; it undoes all the modifications made by the current migration and returns the database to the condition anticipated by the prior migration. This is comparable to installing and uninstalling the migration. When you call one of these methods, just one of them is used.update-database To employ theDown manner, you must explicitly state the upgrade's target migration. The migration API will automatically utilize the old migration if that is the target migration.Down downgrade your database using this way.

77
2/9/2017 1:54:12 AM

Popular Answer

To add to @Ladislav Mrnka's comment: For the first time, I had to use Down(), and it took me some time to get it to work, so:

Update-Database -Target:201407242157114_46

Here is a great justification of how to rewind the database and delete a poor migration, where my most recent migration is 47 (where new content was inserted).

I hope it may aid other aspiring magicians:)



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow