Arjun Menon
Arjun Menon

Reputation: 703

Add a new column as Unique Constraint to table that has value EF 6.0

I am trying to add a new column as Unique key where the table has already data. I am using EF 6.0 and code first approach and I added the property [Index(IsUnique = true)] and generated the Migration Script but when executing I am getting an error as the column added is new and there is no value to it

Upvotes: 0

Views: 388

Answers (1)

zAnthony
zAnthony

Reputation: 342

Try this.

[Index("IX_FirstAndSecond", 2, IsUnique = true)]
public int SecondColumn { get; set; }

Upvotes: 1

Related Questions