Home > Back-end >  Why does running Update-Database on my empty production database not create any tables?
Why does running Update-Database on my empty production database not create any tables?

Time:08-09

I'm using Entity Framework code-first migrations.

During development, I created the database on the development database server, enabled code-first migrations, added an initial migration, ran Update-Database, made some changes to the models, added another migration, ran Update-Database again, etc. Everything works fine.

However, now that I'm ready to have it create the tables on the production database server, it doesn't work.

Here is what I did:

  1. Changed the connection string in the web.config file to point to the production database server
  2. Opened the Package Manager Console
  3. Ran Update-Database

There is no error message. It just says

No pending explicit migrations
Running seed method

I'm using:

  • MigrateDatabaseToLatestVersion
  • AutomaticMigrationsEnabled = false
  • AutomaticMigrationDataLossAllowed = false
  • Entity Framework 6

Am I misunderstanding how migrations are supposed to work? Do I need to do something more than change the connection string to point to the production server and run Update-Database?

Update: I'm an idiot. See my answer below.

CodePudding user response:

Good grief, I'm an idiot. I finally figured out the source of the problem.

While I had changed the connection string in web.config to that of the production database, I had done so in the wrong project! My solution contains both a "Web" project (which is where the Update-Database command was looking) and a "WebAPI" project (which is the one I was editing).

sigh

  • Related