I am using entity framework code first model in a windows form application, I have an existing database in AppData folder and created migration script for it using Add-Migration
. When I run Update-Database
from Package Manager Console, the database gets properly updated. But when I create SETUP.exe for the same project and install that setup, changes are not migrated to database.
Asked
Active
Viewed 207 times
1

Aniket Bhansali
- 630
- 12
- 33
-
1Check here: http://stackoverflow.com/questions/10848746/using-entity-framework-code-first-migrations-in-production – Mats391 Nov 25 '16 at 08:58
-
Database.SetInitializer
(new MigrateDatabaseToLatestVersion – Aniket Bhansali Nov 25 '16 at 09:12()); I am not getting what I need to pass to Configuration parameter. Is it my Configuration class in Migrations folder? -
Yes you add your DatabaseContext and Migration configuration. This wont apply the migrations on installation tho, but instead on first time running. I am not sure if you can apply them during installation. – Mats391 Nov 25 '16 at 09:20
-
Yup, It works! Thanks for comment, it applied migrations on first run, but for now that is enough for me. – Aniket Bhansali Nov 25 '16 at 09:21
-
It is working for upgrading database, but if the database doesn't exist then it fails to create. Can you please tell where I might be going wrong. – Aniket Bhansali Nov 25 '16 at 12:32
-
Use `CreateIfNotExists` https://msdn.microsoft.com/en-us/library/system.data.entity.database.createifnotexists(v=vs.113).aspx – Mats391 Nov 25 '16 at 13:05
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/129044/discussion-between-aniket-bhansali-and-mats391). – Aniket Bhansali Nov 25 '16 at 13:21