Reputation: 45
I have created an Azure Mobile Service project. From the beginning of the project I created my entities and enabled Code First Migrations. During the development process I never had any problem creating new entities, modifying existing ones and updating the database through data migrations. All sweet and nice.
I published my solution to Azure Mobile Services. My database schema was created automatically and everything was playing nice.
After few days I needed to update a field in a table. So updated the entity locally and run the service locally. My local version of my database was updated with my new addition. I uploaded the service to Azure and I was expecting my online database to be updated also. But I get this error
The model backing the 'xxxxx' context has changed since the database was created. Consider using Code First Migrations to update the database.
That is strange, since code first migrations are already enabled. My database was initially created using them. After many days of trying almost everything I deleted the schema of my database at the online version. I run again the service online and it created again the database schema with the last change I did. So I figure out the Azure Mobile Service has no problem to create the schema from the beginning but cannot figure out how to apply schema updates.
Upvotes: 2
Views: 168
Reputation: 17527
I do not recommend this as an answer (so please don't accept it as such), but I ended up so frustrated with the code-first migrations (which, like you, I just could not get to work) that I did this as a work-around while I await enlightenment.
1) Update the data model
For me this was simply adding this line to my Item
class:
public bool IsPublic { get; set; }
2) Manually update the SQL server
You'll find the connection details in the publish profile you can download from the mobile service's dashboard in the Azure Portal. My tSQL command was simply
ALTER TABLE vcollectapi.Items
ADD IsPublic BIT NOT NULL DEFAULT(0)
3) Stop the service checking whether the model backing the context has changed since the last successful migration
There are several answers on how to do this, I followed this one and added the following static constructor to my data context class VCollectAPIContext
static VCollectAPIContext()
{
Database.SetInitializer<VCollectAPIContext>(null);
}
Now my service is back up-and-running and my data remained intact.
Upvotes: 0