1

使用 Orchard 1.6,我已将其添加 public virtual int? BusinessCategory_Id { get; set; }到我的“CustomerPartRecord”表中。并添加

public int? BusinessCategory_Id
    {
        get { return Record.BusinessCategory_Id; }
        set { Record.BusinessCategory_Id = value; }
    }

到我的“CustomerPart”表。在我的迁移文件中,我添加了:

public int UpdateFrom26()
    {
        SchemaBuilder.CreateForeignKey("ProductCategoryRecord_CustomerPartRecord", "CustomerPartRecord", new[] { "BusinessCategory_Id" }, "ProductCategoryRecord", new[] { "Id" });
        return 27;
    }

因此,这应该从“ProductCategoryRecord”表中获取“Id”并将其存储为“CustomerPartRecord”表中名为“BusinessCategory_Id”的 FK。

我之前用其他值尝试过这个并且它已经工作了但是这次我得到了错误:Foreign key 'Umacs_ProductCategoryRecord_CustomerPartRecord' references invalid column 'BusinessCategory_Id' in referencing table 'Umacs_UMACS_Bradmount_CustomerPartRecord'. Could not create constraint. See previous errors.

在日志文件中它告诉我

    2013-07-24 17:38:49,716 [28] Orchard.Data.Migration.DataMigrationManager - An unexpected error orccured while applying migration on UMACS.Bradmount from version 26
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Data.SqlClient.SqlException: Foreign key 'Umacs_ProductCategoryRecord_CustomerPartRecord' references invalid column 'BusinessCategory_Id' in referencing table 'Umacs_UMACS_Bradmount_CustomerPartRecord'.
Could not create constraint. See previous errors.

还尝试删除缓存文件并重新启动devl。服务器。

有任何想法吗?

4

1 回答 1

2

您需要先创建列,然后才能将其设为外键。

于 2013-07-27T08:09:56.217 回答