1

I am having problems with trying to connect MVC to an existing table in a database, when I load up the page it displays this error to me:

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

I have a feeling it's because my Class(Model) doesn't match up with the columns in the database, I have got my connection thing in the web.config and I have given it the name of the class that inherits from DbContext.

I'm not asking for a solution to this I am wondering why I would get this error message.

  • This might help: http://stackoverflow.com/questions/14948205/model-backing-a-db-context-has-changed-consider-code-first-migrations – savner Jul 31 '14 at 20:23
  • This might help also: http://stackoverflow.com/questions/3600175/the-model-backing-the-database-context-has-changed-since-the-database-was-crea – PWilliams0530 Jul 31 '14 at 20:27

1 Answers1

0

Thanks for the links guys, I managed to solve the problem in the end, I had to add this line:

Database.SetInitializer<ChartStoredProcedureDBContext>(null);

To:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        // This line here made it work!
        Database.SetInitializer<ChartStoredProcedureDBContext>(null);

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        AuthConfig.RegisterAuth();
    }
}

which is the Global.asax file and then I have to redirect it to my table name which I used:

[Table("tbl_myTable")]
public class ChartStoredProcedure

This resolved my problem.