1
votes

I have a SQL Server database with more than 50 tables. It was used for my web application written in ASP.NET. Now I write a new ASP.NET MVC 5 web application for new functions under the original web application folder. I create some models (about 10 tables) with code first migration enabled database.

Now I want to deploy the application to remote server. And the database connection still connect to the same existing SQL Server database.

But I always get the error :

Model compatibility cannot be checked because the database does not contain model metadata. Model compatibility can only be checked for databases created using Code First or Code First Migrations.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: Model compatibility cannot be checked because the database does not contain model metadata. Model compatibility can only be checked for databases created using Code First or Code First Migrations.

Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

My code didn't have the models correlate to existing database tables. I don't want my code have the useless model and keep it simple. And I can't drop the existing database. Could any one tell me how can I do?

2
you have to change your connection string in your webconfig, ie. instead of localhost, write IP or name of the server. and for code-first you have to create database on the server then run the script.Shaahin

2 Answers

0
votes

You have to replace your local server Name to IP address of your Live server

   connection string='Data Source=ServerIP,portNumber\SQLEXPRESS2008R2;Initial Catalog=DBName;User ID=Sa;Password=123456789;integrated security=False;'
0
votes

I have found the answer :

In Global.asax, I have added the line the Database.SetInitializer<...>.. It cause the error. Remove it as following , Thank you!

public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            //Database.SetInitializer<MyDBContext>(.....);
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
    }