Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc Orchard 1.6不允许我创建FK_Asp.net Mvc_Orchardcms_Orchardcms 1.6 - Fatal编程技术网

Asp.net mvc Orchard 1.6不允许我创建FK

Asp.net mvc Orchard 1.6不允许我创建FK,asp.net-mvc,orchardcms,orchardcms-1.6,Asp.net Mvc,Orchardcms,Orchardcms 1.6,使用Orchard 1.6,我添加了 公共虚拟整数?BusinessCategory_Id{get;set;}到我的“CustomerPartRecord”表。 并补充说 public int? BusinessCategory_Id { get { return Record.BusinessCategory_Id; } set { Record.BusinessCategory_Id = value; } } 到我的“CustomerPart

使用Orchard 1.6,我添加了 公共虚拟整数?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”,并将其作为名为“BusinessCategory_Id”的FK存储在“CustomerPartRecord”表中

我以前用其他值尝试过这一点,但这次我遇到了错误:
外键“Umacs\u ProductCategoryRecord\u CustomerPartRecord”在引用表“Umacs\u Umacs\u Bradmount\u CustomerPartRecord”中引用了无效列“BusinessCategory\u Id”。
无法创建约束。请参阅前面的错误。

在日志文件中,它告诉我

    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。服务器


有什么想法吗?

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

能否显示在CustomerPartRecord表上创建BusinessCategory\u Id列的迁移代码?我不知道您必须实际为FK创建列。本以为在使用“SchemaBuilder.CreateForeignKey”时会自动完成,但感谢您提供的解决问题的答案,我会将其复制为答案,以便您可以授予它。