代码优先迁移的外键错误:不能删除列

时间:2016-04-06 08:53:12

标签: asp.net-mvc entity-framework foreign-keys ef-migrations

我遇到了Entity Framework的问题并进行了迁移(数据库更新)和外键注释。 我收到的错误消息是:smart wait

driver.execute_script('document.getElementById("demo").innerHTML')

[...]

update-database –verbose

我想要一个0:0 ...... 1的关系。那就是它。

我试图像在这个例子EF Code-First One-to-one relationship: Multiplicity is not valid in Role * in relationship

中那样做
Applying automatic migration: 201604060846578_AutomaticMigration.
IF EXISTS (SELECT name FROM sys.indexes WHERE name = N'IX_OutreachSet_TargetContact' AND object_id = object_id(N'[dbo].[DiagnosticsSets]', N'U'))
    DROP INDEX [IX_OutreachSet_TargetContact] ON [dbo].[DiagnosticsSets]
IF EXISTS (SELECT name FROM sys.indexes WHERE name = N'IX_OutreachSet_TargetContact' AND object_id = object_id(N'[dbo].[MotivationSets]', N'U'))
    DROP INDEX [IX_OutreachSet_TargetContact] ON [dbo].[MotivationSets]
DECLARE @var0 nvarchar(128)
SELECT @var0 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'dbo.MotivationSets')
AND col_name(parent_object_id, parent_column_id) = 'TargetContact';
IF @var0 IS NOT NULL
    EXECUTE('ALTER TABLE [dbo].[MotivationSets] DROP CONSTRAINT [' + @var0 + ']')
ALTER TABLE [dbo].[MotivationSets] DROP COLUMN [TargetContact]

1 个答案:

答案 0 :(得分:0)

我想我自己解决了。 我刚刚这样做了:How to re-create database for Entity Framework?

如果有人还能告诉我为什么会这样,我会很高兴

谢谢!