Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Code First Migration Files Source Control

Wanted to ask this bluntly as I can't seem to find the answer out there.

When I run 'Add-Migration...' 3 new file migration files are created (.cs, .resx, .Designer.cs). In regards to source control, which files should I commit to my repo and what files can I ignore? I'm only interested in the files absolutely necessary to reconstruct my tables if needed.

like image 724
slashNburn Avatar asked Nov 05 '16 20:11

slashNburn


People also ask

How do I code my first migration to an existing database?

Run the Add-Migration InitialCreate command in Package Manager Console. This creates a migration to create the existing schema. Comment out all code in the Up method of the newly created migration. This will allow us to 'apply' the migration to the local database without trying to recreate all the tables etc.

How do I use migration in Entity Framework?

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).

Should I commit EF migrations?

Definitely the migrations should be committed in source control. Deleting migrations will make it impossible for EF to generate future migrations for future changes to an existing database.


1 Answers

When I run 'Add-Migration...' 3 new file migration files are created (.cs, .resx, .Designer.cs). In regards to source control, which files should I commit to my repo and what files can I ignore?

All 3 files are necessary to reconstruct your database.

  • the .cs file contains the Up and Down method to help you, respectively, updgrade or downgrade your database.
  • the .resx file contains the metadata that is used by migrations. It contains the name of the default schema you use (dbo is the default value) and a snapshot of the model at the time the migration was generated.
  • the .Designer.cs is here because of the presence of .resx. It contains properties that make easy to access settings on the .resx file.

All 3 files need to be committed and pushed in your source control and no one should edit them.

like image 131
CodeNotFound Avatar answered Nov 25 '22 04:11

CodeNotFound