MVC代码优先迁移

问题描述 投票:1回答:1

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

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

消息错误是:

表'dbo.Drivers'中的列'Phone'的类型无效,无法用作索引中的键列

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

c# asp.net asp.net-mvc entity-framework migration
1个回答
2
投票

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

 [MaxLength(20)]
 [Index("PhoneAndIdentAndDLExpAndVRNo", Order =1)]
 public string Phone { get; set; }
© www.soinside.com 2019 - 2024. All rights reserved.