每个表中的列名必须是唯一的。表'dbo.Foos'中的列名“StripeRecipientId”被指定多次 [英] Column names in each table must be unique. Column name 'StripeRecipientId' in table 'dbo.Foos' is specified more than once

查看:1066
本文介绍了每个表中的列名必须是唯一的。表'dbo.Foos'中的列名“StripeRecipientId”被指定多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 Foo 的模型类,其中包含这些属性。

I have a model class named Foo that has, among others, these properties.

public string StripeRecipientId { get; set; }

public override bool HasProvidedBillingInformation
{
    get
    {
        // return !string.IsNullOrEmpty(this.StripeRecipientId);

        return false;
    }
}

我已启用迁移,并使用Code First。当我运行 update-database commandlet时,无论是否指定 -Force 选项,我收到此错误:

I have enabled migrations and am using Code First. When I run the update-database commandlet, whether with -Force option is specified or not, I get this error:

每个表格中的列名必须是唯一的。

'dbo.Foos中的列名StripeRecipientId不止一次。

- 检查和三重检查,我的模型和表中只有一列该名称。此列已经由前一次运行的 update-database commandlet创建。

I double-checked and triple checked and there's only one column of that name in my model as well as in the table. This column was created already by a previous run of the update-database commandlet just a while ago.

我是试图删除我的数据库,然后应用迁移,但这意味着我必须创建大量的测试数据,以便能够测试我刚刚工作的功能。

I am tempted to delete my database and then apply the migrations, but that will mean me having to create a lot of test data just to be able to test the feature I am working on just now.

我正在使用Entity Framework v6.1.2。

I am using Entity Framework v6.1.2.

我如何摆脱这个错误?

推荐答案

使用 -IgnoreChanges 标志运行 Add-Migration 命令。然后再次运行 Update-Database

Run the Add-Migration command with the -IgnoreChanges flag. Then run Update-Database again.

-Update -

这些命令应该在包管理器控制台中运行。从主菜单:工具 - > NuGet软件包管理器 - >软件包管理器控制台。

These commands should be run in the Package Manager Console. From the main menu: Tools-> NuGet Package Manager -> Package Manager Console.

这篇关于每个表中的列名必须是唯一的。表'dbo.Foos'中的列名“StripeRecipientId”被指定多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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