在移动服务数据库上启用代码优先迁移时出错 [英] Error While Enabling Code-First Migrations On Mobile Services Database

查看:92
本文介绍了在移动服务数据库上启用代码优先迁移时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Azure移动服务项目(C#后端),我最近创建并附加到Azure SQL数据库。我一直在尝试在该支持数据库上启用代码优先迁移,但是当我尝试更新数据库时,它会引发错误。



我运行了所有常规步骤启用迁移(Enable-Migrations,Add-Migration)。但是当我尝试更新数据库时,它返回以下错误:


无法在表'dbo.Appointments上创建多个聚集索引。在创建另一个之前删除现有的聚簇索引PK_dbo.Appointments。


为什么会发生这种情况?我的数据库中没有任何表,项目几乎是默认的。

解决方案

来自一个自定义的实体类将会工作,但它们不是理想的解决方案。正如EF团队(和其他人)提到的,您需要将这一行添加到Context Configuration构造函数中。

  SetSqlGenerator System.Data.SqlClient,新的EntityTableSqlGenerator()); 

这将在创建迁移时删除您的错误,并允许您通过powershell命令更新数据库。 p>

I have an Azure Mobile Services project (C# backend) that I recently created and attached to an Azure SQL database. I have been trying to enable Code-First Migrations on that backing database, but it throws errors when I try to update the database.

I ran through all of the conventional steps to enable migrations (Enable-Migrations, Add-Migration). But when I try to Update-Database, it returns the following error:

Cannot create more than one clustered index on table 'dbo.Appointments'. Drop the existing clustered index 'PK_dbo.Appointments' before creating another.

Why is this happening? There aren't any tables in my database, and the project is pretty much the default.

解决方案

Several of the answers about deriving from a custom entity class will work, but they are not the ideal solution. As the EF team (and others) have mentioned, you need to simply add this line to your Context Configuration constructor.

 SetSqlGenerator("System.Data.SqlClient", new EntityTableSqlGenerator());

This will remove your errors when creating migrations and allow you to update the database via powershell command.

这篇关于在移动服务数据库上启用代码优先迁移时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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