Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a best or recommended practice for naming Entity Framework migrations?

When using Entity Framework code first migrations is there a best practice for choosing a name for each migration? For example each name might contain a version number or the change(s) made to the model or both.

Add-Migration Added Manager.Employees
Add-Migration Add_Employee_ManagerId
Add-Migration version 2
Add-Migration v2_Add_Employee_ManagerId

Any tips for selecting a good naming strategy for a project with multiple developers and many migrations?

I found a similar question but no answers.

like image 802
user1843640 Avatar asked Sep 09 '15 13:09

user1843640


People also ask

How do I rename my EF migration?

Accepted AnswerYou cannot rename after applying a migration to Database. But you can delete and add another migration with same name or other name.

How do I use migrations in Entity Framework?

Following is the context class. Step 1 − Before running the application you need to enable migration. Step 2 − Open Package Manager Console from Tools → NuGet Package Manger → Package Manger Console. Step 3 − Migration is already enabled, now add migration in your application by executing the following command.

What is Code First migrations in Entity Framework?

Code First Migrations is the recommended way to evolve your application's database schema if you are using the Code First workflow. Migrations provide a set of tools that allow: Create an initial database that works with your EF model. Generating migrations to keep track of changes you make to your EF model.

What is __ Efmigrationshistory?

By default, EF Core keeps track of which migrations have been applied to the database by recording them in a table named __EFMigrationsHistory . For various reasons, you may want to customize this table to better suit your needs.


1 Answers

In the Microsoft docs it states:

The migration name can be used like a commit message in a version control system. For example, if I made changes to save customer reviews of products, I might choose something like AddProductReviews.

So by their provided example of AddProductReviews I'm thinking that Upper Camel Case is what Microsoft recommends.

https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/

like image 91
Zze Avatar answered Oct 08 '22 17:10

Zze