We are using Entity Framework 4.3.1's migrate.exe tool to run database migrations from our TeamCity build server as part of our continuous integration and deployment automation. One of these issues we have been encountering is that the migrate.exe tool does not emit a non-zero exit code when it fails:
C:\<path>\packages\EntityFramework.4.3.1\tools>migrate.exe AppContext /startupdirectory:C:\<path>\bin\Debug /startupconfigurationfile:C:\<path>\Web.config /verbose
<Bunch of successful migrations>
Applying explicit migration: 201202212004585_UpdateTable
VERBOSE: ALTER TABLE [TableA] DROP CONSTRAINT [FK_TableA_TableB]
System.Data.Entity.Migrations.Design.ToolingException: 'FK_TableA_TableB' is not a constraint.
Could not drop constraint. See previous errors.
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMig
ration, Boolean force)
at System.Data.Entity.Migrations.Console.Program.Run()
at System.Data.Entity.Migrations.Console.Program.Main(String[] args)
ERROR: 'FK_TableA_TableB' is not a constraint.
Could not drop constraint. See previous errors.
C:\<path>\packages\EntityFramework.4.3.1\tools>echo %errorlevel%
0
This is causing Team City to pass a build off as "successful" when a migration fails and it should be failed.
Our temporary work-around is to grep the build log for "ERROR:" and fail the build when this occurs, but this solution is crude and we cannot tell if EF failed or some other process with a similar log entry.
Any suggestions for a better work around? Either a way to make migrate.exe behave or a way to get Team City understand that the failure is specific to migrate.exe.