kann nicht gelöscht werden Ich habe ein Problem mit Entity Framework und eine Migration (Datenbank-Update) und Fremdschlüssel-Anmerkungen. Die Fehlermeldung, die ich erhalte, ist nach: update-database –verbose
Fremdschlüsselfehler bei Code-First-Migration: Spalte
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]
[...]
The object 'PK_dbo.MotivationSets' is dependent on column 'TargetContact'.
ALTER TABLE DROP COLUMN TargetContact failed because one or more objects access this column.
Ich habe gerade eine 0 haben mag: 0 ... 1 Beziehung. Das ist es.
würde ich versuche, es zu tun, so wie in diesem Beispiel EF Code-First One-to-one relationship: Multiplicity is not valid in Role * in relationship
public class OutreachSet
{
[Key]
[Display(Name = "Target Contact")]
public string TargetContact { get; set; }
[Display(Name = "Next Outreach Step")]
public string NextOutreachStep { get; set; }
public virtual MotivationSet MotivationSet { get; set; }
}
public class MotivationSet
{
[Key, ForeignKey("OutreachSet")]
public string TargetContact { get; set; }
public string PowerMastery { get; set; }
[Required]
public virtual OutreachSet OutreachSet { get; set; }
}
Wahrscheinlich haben Sie Ihr Modell auf eine Weise geändert, die Migrationen standardmäßig nicht verarbeiten konnten - das Ändern des Identitätsstatus, FK-Umbenennungen, sind Beispiele. Wenn Sie alles löschen und neu anfangen, vermeiden Sie die Umbenennungen und alles wird von Grund auf neu erstellt. http://stackoverflow.com/questions/17894906/ef-migration-for-change-data-type-of-columns –
Was ist, wenn Sie nicht bei Null anfangen können? – TWilly