{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5384","repository_url":"https://api.github.com/repos/aspnet/EntityFramework","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5384/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5384/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5384/events","html_url":"https://github.com/aspnet/EntityFramework/issues/5384","id":155273388,"number":5384,"title":"Int32/Int64 properties with default value automatically annotated with SqlServerValueGenerationStrategy.IdentityColumn in migration","user":{"login":"sergeitemkin","id":12854677,"avatar_url":"https://avatars.githubusercontent.com/u/12854677?v=3","gravatar_id":"","url":"https://api.github.com/users/sergeitemkin","html_url":"https://github.com/sergeitemkin","followers_url":"https://api.github.com/users/sergeitemkin/followers","following_url":"https://api.github.com/users/sergeitemkin/following{/other_user}","gists_url":"https://api.github.com/users/sergeitemkin/gists{/gist_id}","starred_url":"https://api.github.com/users/sergeitemkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergeitemkin/subscriptions","organizations_url":"https://api.github.com/users/sergeitemkin/orgs","repos_url":"https://api.github.com/users/sergeitemkin/repos","events_url":"https://api.github.com/users/sergeitemkin/events{/privacy}","received_events_url":"https://api.github.com/users/sergeitemkin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aspnet/EntityFramework/labels/bug","name":"bug","color":"f7c6c7"},{"url":"https://api.github.com/repos/aspnet/EntityFramework/labels/pri0","name":"pri0","color":"e11d21"}],"state":"open","locked":false,"assignee":{"login":"AndriySvyryd","id":6539701,"avatar_url":"https://avatars.githubusercontent.com/u/6539701?v=3","gravatar_id":"","url":"https://api.github.com/users/AndriySvyryd","html_url":"https://github.com/AndriySvyryd","followers_url":"https://api.github.com/users/AndriySvyryd/followers","following_url":"https://api.github.com/users/AndriySvyryd/following{/other_user}","gists_url":"https://api.github.com/users/AndriySvyryd/gists{/gist_id}","starred_url":"https://api.github.com/users/AndriySvyryd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndriySvyryd/subscriptions","organizations_url":"https://api.github.com/users/AndriySvyryd/orgs","repos_url":"https://api.github.com/users/AndriySvyryd/repos","events_url":"https://api.github.com/users/AndriySvyryd/events{/privacy}","received_events_url":"https://api.github.com/users/AndriySvyryd/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/7","html_url":"https://github.com/aspnet/EntityFramework/milestones/1.0.0","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/7/labels","id":666128,"number":7,"title":"1.0.0","description":"","creator":{"login":"rowanmiller","id":4741851,"avatar_url":"https://avatars.githubusercontent.com/u/4741851?v=3","gravatar_id":"","url":"https://api.github.com/users/rowanmiller","html_url":"https://github.com/rowanmiller","followers_url":"https://api.github.com/users/rowanmiller/followers","following_url":"https://api.github.com/users/rowanmiller/following{/other_user}","gists_url":"https://api.github.com/users/rowanmiller/gists{/gist_id}","starred_url":"https://api.github.com/users/rowanmiller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rowanmiller/subscriptions","organizations_url":"https://api.github.com/users/rowanmiller/orgs","repos_url":"https://api.github.com/users/rowanmiller/repos","events_url":"https://api.github.com/users/rowanmiller/events{/privacy}","received_events_url":"https://api.github.com/users/rowanmiller/received_events","type":"User","site_admin":false},"open_issues":99,"closed_issues":182,"state":"open","created_at":"2014-05-21T19:25:32Z","updated_at":"2016-05-17T23:03:27Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2016-05-17T14:26:00Z","updated_at":"2016-05-17T23:31:41Z","closed_at":null,"body":"After migrating to EF7 RC2 we've noticed that our `int` and `long` properties that are set with `HasDefaultValue` in the `ModelBuilder` are causing the migration script to annotate columns representing those properties with an identity attribute. This, in turn, causes an exception since defaults cannot be created on identity columns.\r\n\r\nHere's a simplified example of the DbContext:\r\n\r\n        public class Entity\r\n        {\r\n            public Guid Id { get; set; }\r\n            public int Column1 { get; set; }\r\n        }\r\n\r\n        public class TestContext : DbContext\r\n        {\r\n            public DbSet<Entity> Entitys { get; set; }\r\n\r\n            public TestContext() { }\r\n\r\n            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)\r\n            {\r\n                var serverName = @\"localhost\";\r\n                var dbName = \"Test\";\r\n\r\n                optionsBuilder\r\n                    .UseSqlServer($\"data source={serverName};initial catalog={dbName};Integrated Security=true;\");\r\n            }\r\n\r\n            protected override void OnModelCreating(ModelBuilder modelBuilder)\r\n            {\r\n                modelBuilder.Entity<Entity>(entity =>\r\n                {\r\n                    entity\r\n                        .Property(e => e.Column1)\r\n                        .HasDefaultValue(1);\r\n                });\r\n            }\r\n        }\r\n\r\n        static void Main(string[] args)\r\n        {\r\n            using (var context = new TestContext())\r\n            {\r\n                context.Database.EnsureCreated();\r\n            }\r\n        }\r\n\r\nWhen creating a migration with Add-Migration, I get the following, which causes an exception when `context.Database.EnsureCreated` is called (*Defaults cannot be created on columns with an IDENTITY attribute. Table 'Entitys', column 'Column1'*): \r\n\r\n        protected override void Up(MigrationBuilder migrationBuilder)\r\n        {\r\n            migrationBuilder.CreateTable(\r\n                name: \"Entitys\",\r\n                columns: table => new\r\n                {\r\n                    Id = table.Column<Guid>(nullable: false),\r\n                    Column1 = table.Column<int>(nullable: false, defaultValue: 1)\r\n                        .Annotation(\"SqlServer:ValueGenerationStrategy\", SqlServerValueGenerationStrategy.IdentityColumn)\r\n                },\r\n                constraints: table =>\r\n                {\r\n                    table.PrimaryKey(\"PK_Entitys\", x => x.Id);\r\n                });\r\n        }\r\n\r\nIs there something I'm missing, or is there a workaround for this?"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/219884649","html_url":"https://github.com/aspnet/EntityFramework/issues/5384#issuecomment-219884649","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5384","id":219884649,"user":{"login":"julianpaulozzi","id":4754958,"avatar_url":"https://avatars.githubusercontent.com/u/4754958?v=3","gravatar_id":"","url":"https://api.github.com/users/julianpaulozzi","html_url":"https://github.com/julianpaulozzi","followers_url":"https://api.github.com/users/julianpaulozzi/followers","following_url":"https://api.github.com/users/julianpaulozzi/following{/other_user}","gists_url":"https://api.github.com/users/julianpaulozzi/gists{/gist_id}","starred_url":"https://api.github.com/users/julianpaulozzi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/julianpaulozzi/subscriptions","organizations_url":"https://api.github.com/users/julianpaulozzi/orgs","repos_url":"https://api.github.com/users/julianpaulozzi/repos","events_url":"https://api.github.com/users/julianpaulozzi/events{/privacy}","received_events_url":"https://api.github.com/users/julianpaulozzi/received_events","type":"User","site_admin":false},"created_at":"2016-05-17T23:31:41Z","updated_at":"2016-05-17T23:31:41Z","body":"+1"}}