Gavin Draper's Blog

Father, Developer, Tech Geek, Extreme Sports Fanatic

@gavdraper | +gavdraper | github | StackOverflow Careers
 

AppHarbor and Entity Framework 4 Code First

I’ve been using AppHarbor for pretty much all my personal projects over the last 6 months and think its a great service, especially now it has GitHub support.

I recently deployed Entity Framework Code First project and had a few problems. After a bit of debugging it turn out the problem was because EF Code First was trying to drop and recreate the database and AppHarbor doesn't give you create permissions. The solution was…

  1. Remove the SQL add-on from AppHarbor and re-add it again as EF had dropped the database.
  2. Change the call to Database.SetInitializer in your context class to look like this
          Database.SetInitializer(new CreateDatabaseIfNotExists<YourContextName>());
  3. Script your EF database and run the script on the AppHarbor database to create your database objects.

Assuming the connection strings are all set up correctly you should be good to go.


 
comments powered by Disqus