添加新字段时出现MobileServiceTableOperationError [英] MobileServiceTableOperationError When Adding New Field

查看:100
本文介绍了添加新字段时出现MobileServiceTableOperationError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于脱机工作清单示例的Azure移动服务项目:

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

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

具有脱机数据的示例应用程序正在按预期方式工作.问题是当我想用新字段修改ToDoItem时.如果我使用以下新字段(Windows应用程序TodoItem类和AzureMobileService应用程序TodoItem类)修改ToDoItem类:

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();

我得到了错误:

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.

PushResult然后出现此错误:

The PushResult then has this error:

{Microsoft.WindowsAzure.MobileServices.Sync.MobileServiceTableOperationError}

据我了解,Azure移动服务支持动态架构,因此我不必手动更新数据库.

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

知道我在做什么错吗?

我正在使用.NET后端.

I am using a .NET backend.

更新1/31/2015

如果我从以下位置修改MobileServiceInitializer:

If I modify the MobileServiceInitializer from:

public class MobileServiceInitializer : DropCreateDatabaseIfModelChanges<MobileServiceContext>

收件人:

public class MobileServiceInitializer : ClearDatabaseSchemaIfModelChanges<MobileServiceContext>

它将正确更新数据库,但是当然会清除表中的所有数据.知道为什么DropCreateDatabaseIfModelChanges会引发错误吗?

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?

推荐答案

这可能是因为Azure移动服务无权删除数据库.在此处查看此博客: http://blogs.msdn.com/b/writingdata_services/archive/2014/03/28/mobile-services-net-backend-initializers-and-model-updates.aspx

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. 删除现有表-遇到您正在谈论的所有问题

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

启用代码优先迁移-允许您保留数据.代码优先迁移有点棘手,因此请为此做好准备,但这是解决您的问题的一种方法.上面的博客对此进行了介绍,但这是在EF中进行迁移的更深入的演示:

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

这篇关于添加新字段时出现MobileServiceTableOperationError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆