I have created a website using MVC4 and I updated the framework to 4.5.1.
Everything works perfectly in development phase. I have enabled the migration with entity framework code first and created a migration "Init".
I have simple membership. When I drop my local database and launch the application, I have all tables perfectly created.

However, when I deploy (FTP) on the production server, I only have a subset of tables.

This is what is done in Global.asax.cs after I tried this
internal void Application_Start() { MvcHandler.DisableMvcResponseHeader = true; Database.SetInitializer( new MigrateDatabaseToLatestVersion<GlobalDbContext, Migrations.Configuration>("DefaultConnection")); AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterAuth(); using (var context = new GlobalDbContext()) { if (!context.Database.Exists()) { // Register the SimpleMembership database without Entity Framework migration schema //((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); context.Database.Create(); } ////context.Database.Initialize(true); //context.Database.Delete(); //context.Database.Create(); } WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "Username", autoCreateTables: true); } Apparently, It's context.Database.Create(); that behaves differently in production.
I already have deployed a full MVC4 application and a full MVC5 application. But it is the first time I deploy a MVC4 application updated to .net 4.5.1 (I don't know if that helps).
Any idea?
Edit (add DbContext sample)
public class GlobalDbContext : DbContext { public GlobalDbContext() : base("DefaultConnection") { }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { Database.SetInitializer<GlobalDbContext> ( new CreateDatabaseIfNotExists<GlobalDbContext>() ); //using model builder here base.OnModelCreating(modelBuilder); } public DbSet<Patient> dbSet1 { get; set; } [***] }
DbContextclass? It is likely that yourDbContextis using a different Connection String, thus not creating tables for your entity classes, even the Membership Provider is able to create it's tables.CreateDatabaseIfNotExistsstrategy, so are you dropping your DB in Prod? If not, this will not do anything. You need to useDropCreateDatabaseIfModelChangesorDropCreateDatabaseAlwaysor your own custom DB initializer. Usually in PROD, you do not want to drop the DB ever, since you'll lose existing data, so you need to go with your custom initializer. Locally, dropping/recreating is not an issue.