asp.net mvc - EntityFramework Code first migrations not running after deploying to Azure -


i'm developing web application in asp.net using code first migrations. works fine locally after deploying azure, code first migrations not executed. have been following this tutorial step step few times have not been able spot wrong on setup. here relevant code:

db context:

public class applicationdbcontext : identitydbcontext<applicationuser> {     public applicationdbcontext() : base("defaultconnection", throwifv1schema: false) {}      public dbset<bc_instance> biocloudinstances { get; set; }      static applicationdbcontext() {}      public static applicationdbcontext create()     {         return new applicationdbcontext();     }      protected override void onmodelcreating(dbmodelbuilder modelbuilder)     {         base.onmodelcreating(modelbuilder);         var conv = new attributetotableannotationconvention<softdeleteattribute, string>(            "softdeletecolumnname",            (type, attributes) => attributes.single().columnname);          modelbuilder.conventions.add(conv);     } } 

connection strings:

(it replaced on publish, in case)

<add name="defaultconnection" connectionstring="data source=.\sqlexpress;initial catalog=bcplatform2;integrated security=true;multipleactiveresultsets=true" providername="system.data.sqlclient" /></connectionstrings> 

code first migrations configuration

internal sealed class configuration : dbmigrationsconfiguration<bcplatform2.models.applicationdbcontext> {     public configuration()     {         automaticmigrationsenabled = false;     }      protected override void seed(bcplatform2.models.applicationdbcontext context)     {         var usermanager = new applicationusermanager(new userstore<applicationuser>(context));         var rolemanager = new applicationrolemanager(new rolestore<applicationrole>(context));         const string name = {name here};         const string password = {pass here};         const string adminrole = {role};         string[] roles = new string[] { adminrole, applicationrole.defaultrolename };          foreach (string role in roles)         {             if (!context.roles.any(r => r.name == role))             {                 rolemanager.createasync(new applicationrole(role));             }         }          if (!context.users.any(u => u.username == name))         {             var user = new applicationuser { username = name, email = name, credit = 10 };              usermanager.create(user, password);             usermanager.addtorole(user.id, adminrole);             usermanager.setlockoutenabled(user.id, false);         }     } } 

publication wizard enter image description here

entity framework section in deployed web.config

<entityframework>   <defaultconnectionfactory type="system.data.entity.infrastructure.localdbconnectionfactory, entityframework">     <parameters>       <parameter value="mssqllocaldb" />     </parameters>   </defaultconnectionfactory>   <providers>     <provider invariantname="system.data.sqlclient" type="system.data.entity.sqlserver.sqlproviderservices, entityframework.sqlserver" />   </providers>   <contexts>     <context type="bcplatform2.models.applicationdbcontext, bcplatform2">       <databaseinitializer type="system.data.entity.migratedatabasetolatestversion`2[[bcplatform2.models.applicationdbcontext, bcplatform2], [bcplatform2.migrations.configuration, bcplatform2]], entityframework, publickeytoken={token}">         <parameters>           <parameter value="defaultconnection_databasepublish" />         </parameters>       </databaseinitializer>     </context>   </contexts> </entityframework> 

connection strings in deployed web.config

<connectionstrings>   <add name="defaultconnection" connectionstring="data source=tcp:{serverid}.database.windows.net,1433;initial catalog={dbid};user id={user};password={password}" providername="system.data.sqlclient" />   <add name="defaultconnection_databasepublish" connectionstring="data source=tcp:{serverid}.database.windows.net,1433;initial catalog={dbid};user id={user};password={password}" providername="system.data.sqlclient" /> </connectionstrings> 

you can update web.config file in solution

it's not necessary provide connection string inside "context" section, because provide in applicationdbcontext constructor.

also, config, can uncheck "execute code first migration" in publication wizard.

your ef section should similar (most important "context" section):

<entityframework> <defaultconnectionfactory type="system.data.entity.infrastructure.localdbconnectionfactory, entityframework">   <parameters>     <parameter value="mssqllocaldb" />   </parameters> </defaultconnectionfactory> <providers>   <provider invariantname="system.data.sqlclient" type="system.data.entity.sqlserver.sqlproviderservices, entityframework.sqlserver" /> </providers> <contexts>   <context type="testwebapp.models.appcontext, testwebapp">     <databaseinitializer type="system.data.entity.migratedatabasetolatestversion`2[[testwebapp.models.appcontext, testwebapp], [testwebapp.migrations.configuration, testwebapp]], entityframework" />   </context> </contexts> 


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -