[英]MVC Code-First Migration
I need to create table Drivers with multiple unique index , why I'm see this message and, how I can solve this? 我需要创建具有多个唯一索引的表Drivers ,为什么会看到此消息,以及如何解决此问题? 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 表'dbo.Drivers'中的'电话'列类型无效,无法用作索引中的键列
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; }
}
The max length for an index column is 900 bytes. 索引列的最大长度为900字节。 The fix is as simple as below. 该修补程序如下所示。
[MaxLength(20)]
[Index("PhoneAndIdentAndDLExpAndVRNo", Order =1)]
public string Phone { get; set; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.