eguneys
eguneys

Reputation: 6396

Code first migration against production database entity framework update database with web config transformations

I have this Web.config

  <connectionStrings>
    <add name="AuthContext" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=mokey;Integrated Security=True" providerName="System.Data.SqlClient" />
   </connectionStrings>

and

Web.Release.config

  <connectionStrings>
    <add xdt:Transform="SetAttributes" xdt:Locator="Match(name)" name="AuthContext" providerName="MySql.Data.MySqlClient" connectionString="server=mysql2.gear.host;database=mokey;persistsecurityinfo=True" />
  </connectionStrings>

So I have two databases, local vs production.

Now when I run update-database local database is updated.

How do I run update-database for production database, that is migrate database to latest version?

Upvotes: 1

Views: 974

Answers (1)

Steve Greene
Steve Greene

Reputation: 12304

You may want to reconsider updating your PRODUCTION database with a code deployment. That's not what EF intended and a lot of DBA's will have issues with a direct update from code.

What we do is generate a script from our migrations that the DBA runs as described here: http://cpratt.co/migrating-production-database-with-entity-framework-code-first/#at_pco=smlwn-1.0&at_si=54ad5c7b61c48943&at_ab=per-12&at_pos=0&at_tot=1

You also have to consider what your database initializer is and set it to null or migratetolatestversion in production. You could also use migrate.exe in your build server to update your database.

Upvotes: 1

Related Questions