Reputation: 31
I need to create table Drivers with multiple unique index, why I'm see this message and, how I can solve this? plz help me.
Problem is I cant do update-database on migrations
Message Error is :
Column 'Phone' in table 'dbo.Drivers' is of a type that is invalid for use as a key column in an index
public class Driver
{
public int DriverID { get; set; }
[Required]
public int Code { get; set; }
[Required]
public string Name { get; set; }
[Required]
[Index("PhoneAndIdentAndDLExpAndVRNo", Order =1)]
public string Phone { get; set; }
public string Email { get; set; }
[Required]
public DateTime DOB { get; set; }
public int Gender { get; set; }
[Required]
public string Address { get; set; }
[Required]
[Index("PhoneAndIdentAndDLExpAndVRNo", Order = 2)]
public string Ident { get; set; }
[Index("PhoneAndIdentAndDLExpAndVRNo", Order = 3)]
public string DLNo { get; set; }
[Required]
public DateTime DLExp { get; set; }
[Index("PhoneAndIdentAndDLExpAndVRNo", Order = 4)]
public string VRNo { get; set; }
[Required]
public DateTime VRExp { get; set; }
public string CarType { get; set; }
public string CarColor { get; set; }
public string CarModel { get; set; }
public bool IsActive { get; set; }
public bool IsOnline { get; set; }
public string TokenID { get; set; }
[Required]
public string Pwd { get; set; }
}
Upvotes: 1
Views: 44
Reputation: 24609
The max length for an index column is 900 bytes. The fix is as simple as below.
[MaxLength(20)]
[Index("PhoneAndIdentAndDLExpAndVRNo", Order =1)]
public string Phone { get; set; }
Upvotes: 2