Search code examples
entity-framework-6entity-framework-migrationsproduction-environment

Add more default data in existing database using ef6 code first migrations


Is it possible to create a migration that includes only data changes? Or is it only a change to the data model that will trigger the creation of a new migration? I found myself in a situation where I realized that some default data weren't included in the last migration and I would like to run a migration that includes data changes only.


Solution

  • Yes, update-database will always run your seed method even if the database hasn't changed. You can use AddOrUpdate commands to make sure you don't add the same data twice.

    See http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application