Q
Q
qwead2018-02-01 18:33:16
PostgreSQL
qwead, 2018-02-01 18:33:16

Asp.net core + EFCore + PostgreSQL: Trouble with migration?

There is an old migration that worked great with MSSQL.

protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Users",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    Login = table.Column<string>(nullable: false),
                    Password = table.Column<string>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Users", x => x.Id);
                });
        }

Now I moved to PostgreSQL and something went wrong ..
when adding data to the table, without explicitly specifying the id, an exception occurs:
null value in column "Id" violates not-null constraint
Failed executing DbCommand (4ms) [Parameters=[@p0='?', @p1='?'], CommandType='Text', CommandTimeout='30']
INSERT INTO "Users" ("Login", "Password")
VALUES (@p0, @p1)
RETURNING "Id";

I suppose the problem is in Sql annotations?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question