eoghank
eoghank

Reputation: 1043

Do code first migrations use a transaction?

We are using Code First migrations and apply them using DBMigrator.Update() from our Application_Start event. Recently when deploying a new migration we got the following exception in from Application_Start:

PK_dbo._MigrationHistory'. Cannot insert duplicate key in object 'dbo._MigrationHistory'. The duplicate key value is (201312020928218_ModifyReport)

This suggest that 1) Application_Start ran more than once and 2) code first migrations do not use a transaction to prevent the same migration being attempted multiple times. If that is so should we move migrations out of the appplication completely and include as part of deployment instead?

Upvotes: 2

Views: 894

Answers (1)

Jukka Puranen
Jukka Puranen

Reputation: 8106

Code First migrations do not use transactions. I guess you could customize migrations to use them, at least in EF6.

I'm kinda battling with similar issues myself at the moment. Other than that I would put the update as part of the deployment rather than it being part of the app.

Upvotes: 2

Related Questions