Re-enabling Migrations? Use the Force, Richard

Whenever I do a presentation on Entity Framework Code First Migrations, I always take a moment to point out the helpful error messages provided by Entity Framework. In an industry plagued by nasty error codes and incomprehensible error messages, EF really stands out. It shows that the team took the time to provide helpful error messages. When something goes wrong in EF, the error message typically tell you what the problem was and what you can do to fix the problem. This isn’t always the case in EF, but they definitely have the most common errors covered off.

Here is an example of one of my favourite error messages from EF Code First:

The model backing the ‘xxContext’ context has changed since the database was created. Consider using Code First Migrations to update the database ( http://go.microsoft.com/fwlink/?LinkId=238269).

This message is perfect in so many ways. It tells me exactly what went wrong and provides the solution to the problem, complete with a link to a blog post with detailed instructions.

While Richard Reukema was presenting his SQL session at Windows Azure Boot Camp in Calgary yesterday, I found a new favourite EF error message:

Migrations have already been enabled in project ‘xx’. To overwrite the existing migrations configuration, use the -Force parameter.

Again, a well crafted error message explaining the problem and providing a solution. I fully endorse solution that involves “using the force”.  Well done EF team…well done.  (unless they mean use the negative force, in which case I revoke my endorsement)