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.
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.
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).
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.
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.
.cs
file contains the Up
and Down
method to help you, respectively, updgrade or downgrade your database..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. .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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With