MVC代码优先迁移

时间:2018-01-03 13:22:57

标签: c# asp.net asp.net-mvc entity-framework migration

我需要创建具有多个唯一索引的表驱动程序, 为什么我看到这个消息,我怎么能解决这个问题?请帮助我。

问题是我无法在迁移时更新数据库

消息错误是:

  

专栏'电话'在表格中,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; }

    }

Image Error

1 个答案:

答案 0 :(得分:2)

索引列的最大长度为900字节。修复方法如下所示。

 [MaxLength(20)]
 [Index("PhoneAndIdentAndDLExpAndVRNo", Order =1)]
 public string Phone { get; set; }