2

When I use entity framework core to do make a code first database application and I update the database, it's generating file with the format "20200729230810_InitialModel.cs". They are the current state of the Models. Should I add them in .gitignore?

  • Why would you want to ignore migrations? do you have a specific problem? because i can assure you if you don't, your devs are going to have them afterwards – TheGeneral Jul 29 '20 at 23:25
  • @TheGeneral No I don't have a specific problem but because they're something like a snapshot and can get old and not up-to-date I thought maybe it would be better to add them to .gitignore, bevore they "spam" the repo with useless files – Moritz Kepplinger Jul 29 '20 at 23:28
  • 3
    Usually, each migration is needed to reproduce the current schema, and also to know how to update the current schema. Without them you cannot recreate the database from scratch, also you cant create a new migration based on that schema – TheGeneral Jul 29 '20 at 23:30
  • But the migrations are built from the entity model classes I've written so they're just something like a intermediate product and can anytime recreated from the existing classes. Or did I get this wrong? – Moritz Kepplinger Jul 29 '20 at 23:35
  • Yeah i think you are thinking about this a little wrong. In code first, EF needs to know where the current db schema is at, what is migrated, what your model looks like, so it can figure out what state you are in, when you try to update the database or add a new migration ect... Try for your self, add a migration, update the database, delete the migration and try to add a migration again. – TheGeneral Jul 29 '20 at 23:49

0 Answers0