title: ASP.NET core deploy to Azure not migrating database
body: <p>I have been working all day by now to get my app deployed to Azure, but can't get it to work, while it previously worked like a charm. </p>
  
  <p>At this point I even deleted the entire Webapp, database and database server.<br>
  I have updated some packages, but at this point there are no errors. </p>
  
  <h1>Tools</h1>
  
  <p>I have put all the tools here that are installed. Maybe there might be a conflict that I am not aware of. </p>
  
  <ul>
  <li>ASP.NET Core >=1.0.1 and EF Core >=1.0.1    </li>
  <li>Visual Studio 2015 Enterprise with Updates (incl ReSharper).</li>
  <li>Entity Framework 6.1.3 Tools for Visual Studio 2015</li>
  <li>Microsoft .NET Core 1.0.1 - SDK 1.0.0 Preview 2-003131 (x64)</li>
  <li>Microsoft .NET Core 1.0.1 - VS 2015 Tooling Preview 2</li>
  <li>Microsoft .NET Core 1.0.3 - SDK 1.0.0 Preview 2-003156 (x64)</li>
  <li>Microsoft .NET Core 1.1.0 - SDK 1.1.0 Preview 2.1-003177 (x64)</li>
  <li>Microsoft .NET Framework 4.5 Multi-Targeting Pack</li>
  <li>Microsoft .NET Framework 4.5.1 Multi-Targeting Pack</li>
  <li>Microsoft .NET Framework 4.5.1 Multi-Targeting Pack (ENU)</li>
  <li>Microsoft .NET Framework 4.5.1 SDK</li>
  <li>Microsoft .NET Framework 4.5.2 Multi-Targeting Pack</li>
  <li>Microsoft .NET Framework 4.5.2 Multi-Targeting Pack (ENU)</li>
  <li>Microsoft .NET Framework 4.6 SDK</li>
  <li>Microsoft .NET Framework 4.6 Targeting Pack</li>
  <li>Microsoft .NET Framework 4.6 Targeting Pack (ENU)</li>
  <li>Microsoft .NET Framework 4.6.1 SDK</li>
  <li>Microsoft .NET Framework 4.6.1 Targeting Pack</li>
  <li>Microsoft .NET Framework 4.6.1 Targeting Pack (ENU)</li>
  <li>Microsoft .NET Version Manager (x64) 1.0.0-rc1</li>
  <li>Microsoft Azure App Service Tools v2.9.6 - Visual Studio 2015</li>
  <li>Microsoft Azure Authoring Tools - v2.9.5.1</li>
  <li>Microsoft Azure Command Line Tools</li>
  <li>Microsoft Azure Libraries for .NET - v2.9</li>
  <li>Microsoft Azure Tools for Visual Studio 2015 - v2.9</li>
  <li>Microsoft Web Deploy 3.6</li>
  <li>Microsoft Web Platform Installer 5.0</li>
  </ul>
  
  <h2>project.json</h2>
  
  <pre><code>{
    "buildOptions": {
      "emitEntryPoint": true,
      "preserveCompilationContext": true
    },
    "dependencies": {
      "Microsoft.AspNetCore.AzureAppServicesIntegration": "1.0.0",
      "BundlerMinifier.Core": "2.2.281",
      "CsvHelper": "2.16.3",
      "Microsoft.ApplicationInsights.AspNetCore": "1.0.2",
      "Microsoft.AspNetCore.Authentication.Cookies": "1.0.1",
      "Microsoft.AspNetCore.Diagnostics": "1.0.1",
      "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.1",
      "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.1",
      "Microsoft.AspNetCore.Mvc": "1.0.2",
      "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview4-final",
      "Microsoft.AspNetCore.Routing": "1.0.2",
      "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
      "Microsoft.AspNetCore.Server.Kestrel": "1.0.2",
      "Microsoft.AspNetCore.StaticFiles": "1.0.1",
      "Microsoft.EntityFrameworkCore": "1.0.2",
      "Microsoft.EntityFrameworkCore.Design": "1.0.2",
      "Microsoft.EntityFrameworkCore.SqlServer": "1.0.2",
      "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.2",
      "Microsoft.EntityFrameworkCore.Tools": {
        "type": "build",
        "version": "1.0.0-preview4-final"
      },
      "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
      "Microsoft.Extensions.Configuration.Json": "1.1.0",
      "Microsoft.Extensions.Configuration.UserSecrets": "1.0.1",
      "Microsoft.Extensions.Logging": "1.1.0",
      "Microsoft.Extensions.Logging.Console": "1.0.1",
      "Microsoft.Extensions.Logging.Debug": "1.0.1",
      "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.1",
      "Microsoft.NETCore.App": "1.0.3",
      "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0",
      "Microsoft.VisualStudio.Web.CodeGeneration.Tools": "1.0.0-preview4-final",
      "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
        "type": "build",
        "version": "1.0.0-preview4-final"
      }
    },
    "frameworks": {
      "netcoreapp1.0": {
        "imports": [
          "dotnet5.6",
          "portable-net45+win8"
        ]
      }
    },
    "publishOptions": {
      "include": [
        "wwwroot",
        "**/*.cshtml",
        "appsettings.json",
        "web.config"
      ]
    },
    "runtimeOptions": {
      "configProperties": {
        "System.GC.Server": true
      }
    },
    "scripts": {
      "prepublish": [ "bower install", "dotnet bundle" ],
      "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
    },
    "tools": {
      "BundlerMinifier.Core": "2.2.281",
      "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
      "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
      "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
      "Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
      "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
        "version": "1.0.0-preview2-final",
        "imports": [
          "portable-net45+win8+dnxcore50",
          "portable-net45+win8"
        ]
      }
    },
    "userSecretsId": "aspnet-Verbonding-67a1a892-cfc3-493a-bb8c-5ddc0637d3db",
    "runtimes": {
      "win10-x64": {}
    }
  }
  </code></pre>
  
  <h2>web.config</h2>
  
  <p>These are the default settings</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;    
    &lt;system.webServer&gt;
      &lt;handlers&gt;
        &lt;add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/&gt;
      &lt;/handlers&gt;
      &lt;aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <h2>appsettings.json</h2>
  
  <pre><code>{
    "ApplicationInsights": {
      "InstrumentationKey": ""
    },
    "ConnectionStrings": {
      "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=######;Trusted_Connection=True;MultipleActiveResultSets=true"
    },
    "Logging": {
      "IncludeScopes": false,
      "LogLevel": {
        "Default": "Debug",
        "System": "Information",
        "Microsoft": "Information"
      }
    }
  }
  </code></pre>
  
  <h2>bundleconfig.json</h2>
  
  <p>These are the default settings</p>
  
  <pre><code>[
    {
      "outputFileName": "wwwroot/css/site.min.css",
      "inputFiles": [
        "wwwroot/css/site.css"
      ]
    },
    {
      "outputFileName": "wwwroot/js/site.min.js",
      "inputFiles": [
        "wwwroot/js/site.js"
      ],
      "minify": {
        "enabled": true,
        "renameLocals": true
      },
      "sourceMap": false
    }
  ]
  </code></pre>
  
  <h2>Startup.cs</h2>
  
  <pre><code>using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
  using Microsoft.EntityFrameworkCore;
  using Microsoft.Extensions.Configuration;
  using Microsoft.Extensions.DependencyInjection;
  using Microsoft.Extensions.Logging;
  using Verbonding.Data;
  using Verbonding.Models;
  using Verbonding.Services;
  using Microsoft.AspNetCore.Identity;
  
  namespace Verbonding
  {
      public class Startup
      {
          public Startup(IHostingEnvironment env)
          {
              var builder = new ConfigurationBuilder()
                  .SetBasePath(env.ContentRootPath)
                  .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                  .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
  
              if (env.IsDevelopment())
              {
                  // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                  builder.AddUserSecrets();
  
                  // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
                  builder.AddApplicationInsightsSettings(developerMode: true);
              }
  
              builder.AddEnvironmentVariables();
              Configuration = builder.Build();
          }
  
          public IConfigurationRoot Configuration { get; }
  
          // This method gets called by the runtime. Use this method to add services to the container.
          public void ConfigureServices(IServiceCollection services)
          {
              // Add framework services.
              services.AddApplicationInsightsTelemetry(Configuration);
  
              services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
                  options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  
              services.AddIdentity&lt;ApplicationUser, IdentityRole&gt;()
                  .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;()
                  .AddDefaultTokenProviders();
  
              services.AddMvc();
  
              // Add application services.
              services.AddTransient&lt;IEmailSender, AuthMessageSender&gt;();
              services.AddTransient&lt;ISmsSender, AuthMessageSender&gt;();
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(
              IApplicationBuilder app, 
              IHostingEnvironment env, 
              ILoggerFactory loggerFactory,
              ApplicationDbContext context)
          {
              loggerFactory.AddConsole(Configuration.GetSection("Logging"));
              loggerFactory.AddDebug();
  
              app.UseApplicationInsightsRequestTelemetry();
  
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
                  app.UseDatabaseErrorPage();
                  app.UseBrowserLink();
              }
              else
              {
                  app.UseExceptionHandler("/Home/Error");
              }
  
              app.UseApplicationInsightsExceptionTelemetry();
  
              app.UseStaticFiles();
  
              app.UseIdentity();
  
              // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
  
              app.UseMvc(routes =&gt;
              {
                  routes.MapRoute(
                      name: "default",
                      template: "{controller=Home}/{action=Index}/{id?}");
              });
  
              var userManager = app.ApplicationServices.GetService &lt; UserManager&lt;ApplicationUser&gt;&gt;();
              DbInitializer.Initialize(context, userManager, Configuration["Password"]);
          }
      }
  }
  </code></pre>
  
  <h1>Publish</h1>
  
  <h2>Connection</h2>
  
  <p>The connection settings are set by Visual Studio / Azure after connecting to Azure
  <a href="https://i.stack.imgur.com/zIK5h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zIK5h.png" alt="Connection"></a></p>
  
  <h2>Settings</h2>
  
  <p>I thinks this is where it might go wrong.<br>
  There is a text saying <code>Discovering data contexts</code>. I would expect here to see my context class, but after a couple of seconds it stops and does not show anything
  <a href="https://i.stack.imgur.com/LYSxl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LYSxl.png" alt="Settings"></a></p>
  
  <h2>Settings after discovering data contexts</h2>
  
  <p>The connection string is also added automatically by Visual Studio / Azure. I have checked the values in the connection string and they seem to be all right.
  <a href="https://i.stack.imgur.com/kzIrF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kzIrF.png" alt="Settings after discovering data contexts"></a></p>
  
  <h1>Some things I have already tried:</h1>
  
  <h2>Update packages</h2>
  
  <p>Updating the packages to version 1.1.0. This did not have the desired effect. If anything it seemed to make things worse. In the end I ended up installing to version 1.0.1 to 1.0.3</p>
  
  <h2>Clean installation on Azure</h2>
  
  <p>I removed the WebApp, database and database server and reinstalled them. </p>
  
  <h2>Clean and rebuild the project</h2>
  
  <p>I have cleaned and rebuilt the project a couple of times, and even every time I made some changes. Did not solve anything.</p>
  
  <h2>Add code to web.config</h2>
  
  <pre><code>&lt;appSettings&gt;
      &lt;add key="MigrateDatabaseToLatestVersion" value="true" /&gt;
  &lt;/appSettings&gt;
  </code></pre>
  
  <p>This did not have any effect, but it also did not give any errors.</p>
  
  <h1>Azure portal</h1>
  
  <p>I started looking at what happened at the Azure portal, here I noticed a couple of things. </p>
  
  <h2>Web app deployed</h2>
  
  <p>The web app is deployed, but the database has not migrated. As long as I do not hit a page that needs to look into the database, everything works fine. </p>
  
  <h2>Database queries</h2>
  
  <p>While there is nothing in the database (except for the default tables), there seem to be some queries executed.<br>
  <a href="https://i.stack.imgur.com/vQkjS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vQkjS.png" alt="Database queries"></a></p>
  
  <p>I really hope someone is seeing this and can tell me what is going on here. </p>
  
  <p>Thanks in advance. </p>