{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework6/issues/51","repository_url":"https://api.github.com/repos/aspnet/EntityFramework6","labels_url":"https://api.github.com/repos/aspnet/EntityFramework6/issues/51/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework6/issues/51/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework6/issues/51/events","html_url":"https://github.com/aspnet/EntityFramework6/issues/51","id":172470391,"number":51,"title":"IndexAttribute or IndexAnnotation not working while initializing MySQL","user":{"login":"euyuil","id":1539596,"avatar_url":"https://avatars.githubusercontent.com/u/1539596?v=3","gravatar_id":"","url":"https://api.github.com/users/euyuil","html_url":"https://github.com/euyuil","followers_url":"https://api.github.com/users/euyuil/followers","following_url":"https://api.github.com/users/euyuil/following{/other_user}","gists_url":"https://api.github.com/users/euyuil/gists{/gist_id}","starred_url":"https://api.github.com/users/euyuil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/euyuil/subscriptions","organizations_url":"https://api.github.com/users/euyuil/orgs","repos_url":"https://api.github.com/users/euyuil/repos","events_url":"https://api.github.com/users/euyuil/events{/privacy}","received_events_url":"https://api.github.com/users/euyuil/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aspnet/EntityFramework6/labels/closed-external","name":"closed-external","color":"777777"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-22T14:42:07Z","updated_at":"2016-08-31T20:12:25Z","closed_at":"2016-08-31T19:12:21Z","body":"I haven't tested with SQL Server yet and am not sure if the issue is only for MySQL.\r\n\r\nPackage versions:\r\n* EntityFramework 6.1.3\r\n* MySql.Data 6.9.9\r\n* MySql.Data.Entity 6.9.9\r\n\r\nSimplified code:\r\n```\r\npublic class MyDbContext : DbContext\r\n{\r\n    public MyDbContext() : base(\"MyDbContextConnectionString\")\r\n    {\r\n        Database.SetInitializer(new MyDbInitializer());\r\n    }\r\n\r\n    public DbSet<User> Users { get; set; }\r\n\r\n    protected override void OnModelCreating(DbModelBuilder modelBuilder)\r\n    {\r\n        // The following code doesn't work either.\r\n        // modelBuilder.Entity<User>()\r\n        //     .Property(e => e.Mobile)\r\n        //     .HasColumnAnnotation(\r\n        //         IndexAnnotation.AnnotationName,\r\n        //         new IndexAnnotation(new IndexAttribute(\"IX_Mob\") { IsUnique = true }));\r\n    }\r\n}\r\n\r\npublic class MyDbInitializer : DropCreateDatabaseAlways<MyDbContext>\r\n{\r\n}\r\n\r\npublic class User\r\n{\r\n    [Key]\r\n    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]\r\n    public long Id { get; set; }\r\n\r\n    [Required]\r\n    public string Name { get; set; }\r\n\r\n    [Required]\r\n    [Index(IsUnique = true)]\r\n    public string Mobile { get; set; }\r\n}\r\n\r\ninternal static void Main(string[] args)\r\n{\r\n    using (var context = new MyDbContext())\r\n    {\r\n        // ...\r\n    }\r\n}\r\n```\r\n\r\nI expect the table to be created with a primary key `Id` and a unique index for column `Mobile`. But the result was that a primary key index for `Id` was created, and a redundant unique index for `Id` was also created, but the expected unique index for `Mobile` was not.\r\n\r\nScreenshots from MySQL Workbench:\r\n\r\n![s1](https://cloud.githubusercontent.com/assets/1539596/17858612/f354c71e-68b8-11e6-8b81-c1eac1de1176.png)\r\n\r\n![s2](https://cloud.githubusercontent.com/assets/1539596/17858626/f9d23c52-68b8-11e6-807e-272dfa6d3ce7.png)\r\n\r\nFull code and project files:\r\n\r\n[eftest.zip](https://github.com/aspnet/EntityFramework6/files/430385/eftest.zip)"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework6/issues/comments/243885834","html_url":"https://github.com/aspnet/EntityFramework6/issues/51#issuecomment-243885834","issue_url":"https://api.github.com/repos/aspnet/EntityFramework6/issues/51","id":243885834,"user":{"login":"gmartinezsan","id":16069822,"avatar_url":"https://avatars.githubusercontent.com/u/16069822?v=3","gravatar_id":"","url":"https://api.github.com/users/gmartinezsan","html_url":"https://github.com/gmartinezsan","followers_url":"https://api.github.com/users/gmartinezsan/followers","following_url":"https://api.github.com/users/gmartinezsan/following{/other_user}","gists_url":"https://api.github.com/users/gmartinezsan/gists{/gist_id}","starred_url":"https://api.github.com/users/gmartinezsan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gmartinezsan/subscriptions","organizations_url":"https://api.github.com/users/gmartinezsan/orgs","repos_url":"https://api.github.com/users/gmartinezsan/repos","events_url":"https://api.github.com/users/gmartinezsan/events{/privacy}","received_events_url":"https://api.github.com/users/gmartinezsan/received_events","type":"User","site_admin":false},"created_at":"2016-08-31T20:12:25Z","updated_at":"2016-08-31T20:12:25Z","body":"Hi, I added a bug so you can follow up @euyuil if you like. We'll check if there is any issue in the MySQL provider.\r\n\r\nHere's the link of the bug.\r\nhttp://bugs.mysql.com/bug.php?id=82828\r\n\r\nFeel free to subscribe.\r\n\r\nThanks!"}}
{"actor":{"display_login":"gmartinezsan"}}