I am using Code-First migrations. Now I want my application when published to a new server to create a database and all tables for the model.
I don’t want to use auto-migrations because I want to keep track of database versioning.
But when I deploy my application to a new server I don’t want it to perform all steps to come to the current model (e.g adding tables/columns which in later revisions are deleted).
I would like to know if there is a way to create one migration that contains the whole (POCO) data model.
When you change the connection string to target your new database, EF will look to compare your model, and it’s migrations with what exists on the database. If nothing exists (new database) It will then create a database to match what you have, by implementing every migration in order for you. If you wanted to see the generated sql before implementing, run:
In the package manager console and see what gets generated.
It will look something like:
Even if you have tons of migrations, it will combine them all into a single script and implement them all at once.