efcore.pg: Unable to create sequence column in postgresql using migration

Hi, I have created the attached migrations as below

migrationBuilder.CreateTable(
    name: "ToDoItems",
    columns: table => new
    {
        Id = table.Column<int>(nullable: false),
        Name = table.Column<string>(nullable: true)
    }
    , constraints: table =>
    {
        table.PrimaryKey("PK_ToDoItems", x => x.Id);

    }
);
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    modelBuilder.Entity("DataAccessLayer.Model.ToDoItem", b =>
    {
        b.Property<int>("Id").**ValueGeneratedOnAdd();**
        b.Property<string>("Name");
        b.HasKey("Id");
        b.ToTable("ToDoItems");
    });
}

It can bee seen that we have added ValueGeneratedOnAdd. But during the insertion the integer sequence is not getting generated and since ID is primary key the insertion is failing.

Point to note it is new database.

Any help/suggestion in this regard will be of immense help.

Thanks and regards Venkatesh Srini

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 18 (3 by maintainers)

Most upvoted comments

For me to migrate assembly you need regenerate migrations after adding Npgsql.EntityFrameworkCore.PostgreSQL, after that it worked like charm. All that identity columns everything will taken care by add-migrations command line or dotnet ef migrations add command line

OK thanks. Unfortunately it will probably take me a bit of time to get to this - am very busy with other things at the moment.