4

When i trying to do update for my migration,if my migration is not synchronized With my SQL database structure i get this message:

There is already an object named 'something*' in the database

In entity framework 6 i could use 'Ignore Changes' but in entity framework 7 I need to delete my database and then migrate.. Is there any solution?

Ashley Medway
  • 7,151
  • 7
  • 49
  • 71
WbbAndMobile
  • 121
  • 1
  • 3
  • How has it become out of sync, with EF7 you should create a migration whenever you plan to update a live database. The idea being a test database you use automatic migrations because you don't care about deleting and starting fresh. – Ashley Medway Feb 11 '16 at 10:23
  • Also note EF7 is now called EF-core – Ashley Medway Feb 11 '16 at 10:23
  • Lets say I changed my 'DB SET' and add some props to some entities. If i want to migrate i need first to delete These new props and then i can Migrate. Is there any way to avoid this and add new props and ignore my old Structure , and override it? – WbbAndMobile Feb 11 '16 at 10:53
  • Why would you want to do this? Leave old now properties in the database but not in the model. Thats not how model first works. The model determines how the database will look. If you want to leave the property then leave the property in the code. You could add an obsolete attribute to ensure its not used but if you want it in your database and you are using model first, then your database will be as your model is. – Ashley Medway Feb 11 '16 at 11:35
  • if all my old migrations file deleted – WbbAndMobile Feb 11 '16 at 13:07
  • Don't delete them! If this situation does happen then create a new Init migration then make changes. – Ashley Medway Feb 11 '16 at 13:58
  • but what about git? if one developer is working on his migrations and other developer is working on his migrations – WbbAndMobile Mar 28 '16 at 14:48
  • I used IgnoreChanges often if EF6 - primarily to begin using migrations on existing projects. Looks like for now they recommend just commenting out the Up() code. https://github.com/aspnet/EntityFramework/issues/4237 – Steve Greene Apr 20 '16 at 16:15
  • 1
    There is a similiar discussion here: http://stackoverflow.com/questions/36741793/ef-7-migration-to-existing-database – Will Huang Apr 12 '17 at 15:16

0 Answers0