locked
Code first deployment problem RRS feed

  • Question

  • I am developing mvc 4 application using code first approach. I use this initialization 

    Database.SetInitializer(new DropCreateDatabaseIfModelChanges<AASCCUContext>());

    inside my global.asax. 

    when I deploy it on my local server it work fine. it create database and so on. but when I host the application on cloud, it show me this 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.
    
    Stack Trace: 
    
    
    [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.]
       System.Data.Entity.Internal.ModelCompatibilityChecker.CompatibleWithModel(InternalContext internalContext, ModelHashCalculator modelHashCalculator, Boolean throwIfNoMetadata) +221
       System.Data.Entity.DropCreateDatabaseIfModelChanges`1.InitializeDatabase(TContext context) +218
       System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +66
       System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +225
       System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +208
       System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +235
       System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +36
       System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +71
       System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +21
       System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +44
       System.Linq.Queryable.OrderByDescending(IQueryable`1 source, Expression`1 keySelector) +85
       BinApp.AASCCU.Website.Controllers.HomeController.Index() +218
       lambda_method(Closure , ControllerBase , Object[] ) +79
       System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +274
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
       System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +120
       System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +452
       System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +15
       System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +33
       System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +240
       System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
       System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
    
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
    plz help me! 

    binyam

    Tuesday, January 29, 2013 2:23 PM

All replies

  • I am developing mvc 4 application using code first approach. I use this initialization 

    Database.SetInitializer(new DropCreateDatabaseIfModelChanges<AASCCUContext>());

    inside my global.asax. 

    when I deploy it on my local server it work fine. it create database and so on. but when I host the application on cloud, it show me this 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.
    
    Stack Trace: 
    
    
    [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.]
       System.Data.Entity.Internal.ModelCompatibilityChecker.CompatibleWithModel(InternalContext internalContext, ModelHashCalculator modelHashCalculator, Boolean throwIfNoMetadata) +221
       System.Data.Entity.DropCreateDatabaseIfModelChanges`1.InitializeDatabase(TContext context) +218
       System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +66
       System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +225
       System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +208
       System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +235
       System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +36
       System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +71
       System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +21
       System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +44
       System.Linq.Queryable.OrderByDescending(IQueryable`1 source, Expression`1 keySelector) +85
       BinApp.AASCCU.Website.Controllers.HomeController.Index() +218
       lambda_method(Closure , ControllerBase , Object[] ) +79
       System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +274
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
       System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +120
       System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +452
       System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +15
       System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +33
       System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +240
       System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
       System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
    
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
    plz help me! 

    binyam

    • Merged by Alexander Sun Thursday, January 31, 2013 2:30 AM Duplicate
    Tuesday, January 29, 2013 2:27 PM
  • Thursday, January 31, 2013 2:27 AM
  • Can you look at the database server? Does the _MigrationsHistoryTable exist?

    This will happen if there is no MigrationsHistory table in the database, perhaps you are missing permissions on the host to create a system table in the database?

    EDIT: I was just told that EF will ignore an error in making the MigrationsHistory table a system table and it will instead just become a normal table. So this is unlikely to be the cause of your issue.

    I'll look into it a bit and see if I can reproduce it. Can you give me some more details about the cloud environment?


    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.


    Friday, February 1, 2013 7:34 PM
  • Hi, 

    Its a Entity say for you "I dont believe in this base, I did not do that..."
    Solve using migrations... On your connectinstring appoint to production Base

    Open VS, Run these steps in your "Package Manage Console":

    before...

    Add-Migration InitialMigrations -IgnoreChanges

    After:

    update-database -verbose     

    These create a reference in your DB to current Context used by your App...

    Good luck! Bye!.

    Friday, April 18, 2014 9:13 PM