![]() ![]() ![]() Later when you run the update-database command nothing will happen because the database already exists.) That's okay, it just means you won't run a test of the migrations code before you deploy the database. (If you missed the step above that directs you to change the database name, Migrations will find the existing database and automatically do the add-migration command. The enable-migrations command creates a Migrations folder in the ContosoUniversity project, and it puts in that folder a Configuration.cs file that you can edit to configure Migrations. This isn't required but you'll see later why it's a good idea.įrom the Tools menu, select NuGet Package Manager > Package Manager Console.Īt the PM> prompt enter the following commands: enable-migrations This change sets up the project so that the first migration creates a new database. Īlso in the application Web.config file, change the name of the database in the connection string to ContosoUniversity2. In this tutorial, you'll deploy the application, and to prepare for that you'll enable Migrations.ĭisable the initializer that you set up earlier by commenting out or deleting the contexts element that you added to the application Web.config file. The Code First Migrations feature solves this problem by enabling Code First to update the database schema instead of dropping and re-creating the database. When the application is running in production, it is usually storing data that you want to keep, and you don't want to lose everything each time you make a change such as adding a new column. This method of keeping the database in sync with the data model works well until you deploy the application to production. When you add, remove, or change entity classes or change your DbContext class, the next time you run the application it automatically deletes your existing database, creates a new one that matches the model, and seeds it with test data. You have configured the Entity Framework to automatically drop and re-create the database each time you change the data model. When you develop a new application, your data model changes frequently, and each time the model changes, it gets out of sync with the database. Connection Resiliency and Command Interception. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |