asp.net mvc 4 - Database migration using code first in mvc 4 -


i have created mvc 4 application using code first , accordingly database , table generated want delete 1 column (from backend) of table. want know there way changes can occur in code automatically according change in database.

through package manager console using migration technique

pm> enable-migrations -enableautomaticmigrations 

in code configuration following

public configuration() {     automaticmigrationsenabled = true;     automaticmigrationdatalossallowed = true; } 

now when model changes following.

pm> update-database 

doing through code

use dropcreatedatabasealways initializer database. recreate database during first usage of context in app domain:

database.setinitializer(new dropcreatedatabasealways<yourcontextname>()); 

actually if want seed database, create own initializer, inherited dropcreatedatabasealways:

public class myinitializer : dropcreatedatabasealways<yourcontextname> {      protected override void seed(magnatecontext context)      {          // seed database here      } } 

and set before first usage of context

database.setinitializer(new myinitializer()); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -