I have an existing Code First model created using Entity Framework. Tables are already created and SQL Express and have records in most of the tables.
Now I wanted to add a new table using Code First approach.
The problem is that I haven't found any simple solution to make this addition automatic. I tried the following:
- Using Update-Database -ConnectionStringName
- does not work as this wants to remove all the tables first, even if my update was just an addition of a new table
Adding to MyContext constructor the following line:
Database.SetInitializer<MyContext>(new MigrateDatabaseToLatestVersion<MyContext, Configuration>());
- again, does not work as this does not expect any table to be present in a database. Frankly speaking why is it called "migration" when it cannot cater for migrating existing data? It should be called "Creation"?
The only way it works is a manual workaround to backup all the existing data to CSV, remove the entire database and then using BULK INSERT to put the data back. However this is lenghtly manual operation that I would like to avoid.
Is it possible that EF6 still does not handle such a basic model change automatically?