MobileServiceTableOperationError When Adding New Field

 ̄綄美尐妖づ 提交于 2019-12-12 04:25:20

问题


I have an Azure Mobile Services project that is based off of the offline to do list example:

http://azure.microsoft.com/en-us/documentation/articles/mobile-services-windows-store-dotnet-get-started-offline-data/

The example application with offline data is working as expected. The problem is when I want to modify the ToDoItem with a new field. If I modify the ToDoItem class with a new field (both the Windows app TodoItem class and the AzureMobileService app TodoItem class) with the following:

[JsonProperty(PropertyName = "NewData")]
public byte[] NewData { get; set; } 

When I try to add a new item:

await MobileService.SyncContext.PushAsync();

I get the error:

A first chance exception of type 'Microsoft.WindowsAzure.MobileServices.Sync.MobileServicePushFailedException' occurred in mscorlib.dll

Additional information: Push operation has failed. See the PushResult for details.

The PushResult then has this error:

{Microsoft.WindowsAzure.MobileServices.Sync.MobileServiceTableOperationError}

It is my understanding that the Azure Mobile Service supports Dynamic Schema, so I should not have to manually update the database.

Any idea what I am doing wrong?

I am using a .NET backend.

Update 1/31/2015

If I modify the MobileServiceInitializer from:

public class MobileServiceInitializer : DropCreateDatabaseIfModelChanges<MobileServiceContext>

to:

public class MobileServiceInitializer : ClearDatabaseSchemaIfModelChanges<MobileServiceContext>

It will correctly update the database, but of course clears all of my data in the table. Any idea why DropCreateDatabaseIfModelChanges is throwing the error?


回答1:


This may be because Azure Mobile Services doesn't have permission to Drop your database. See this blog here: http://blogs.msdn.com/b/writingdata_services/archive/2014/03/28/mobile-services-net-backend-initializers-and-model-updates.aspx

The blog lays out two options, if this is your problem:

  1. Drop existing tables - Which has all the problems you're talking about

  2. Enable Code First Migration - which allows you to keep your data. Code First migration is a bit tricky, so be prepared for that, but it is one solution for your problem. The Blog above goes into this a bit but this is a more depth demo of doing a Migration in EF: https://msdn.microsoft.com/en-us/data/JJ591621.aspx



来源:https://stackoverflow.com/questions/28169814/mobileservicetableoperationerror-when-adding-new-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!