![]() Scaffolds a new migration script and adds it to the project. ConnectionString -ConnectionProviderName Scaffolds a migration script for any pending model changes.Īdd-Migration To know more about add-migration command parameters, execute get-help add-migration or get-help add-migration -detailed commands in PMC, as shown below. This is the advantage over automated migration. You may also write your own custom code for additional configurations. ![]() The above command will create a _SchoolDB-v1.cs file with the Up() and Down() methods, as shown below.Īs you can see, the Up() method contains code for creating database objects and the Down() method contains code for dropping or deleting database objects. Now, you have to create a migration class using the Add-Migration command with the name of your migration class, as shown below. Protected override void OnModelCreating( DbModelBuilder modelBuilder) Public SchoolDBContext(): base( "SchoolDB")ĭatabase.SetInitializer( new MigrateDatabaseToLatestVersion()) Now, you need to set the database initializer MigrateDatabaseToLatestVersion in your context class, as shown below. The Enable-Migrations command will create the Configuration class derived from DbMigrationsConfiguration with AutomaticMigrationsEnabled = false. Open the Package Manager Console from Tools → Library Package Manager → Package Manager Console and then run the enable-migrations command (make sure that the default project is the project where your context class is). To use code-based migrations, first execute the enable-migrations command in the Package Manager Console.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |