Postgres Identity column does not work
See original GitHub issueDescribe the bug The identity option, as well the the default sequential id value do not work with postgres
To Reproduce
services.AddFluentMigratorCore()
.ConfigureRunner(fluentMigratorBuilder => fluentMigratorBuilder
.AddPostgres()
.WithGlobalConnectionString(connectionString)
.ScanIn(AssemblyWithMigrations).For.Migrations()
)
.AddLogging(lb => lb.AddFluentMigratorConsole());
With the uuid-ossp installed as an extension on my postgres database the following migration results in an integer primary key:
Create.Table("Players")
.WithColumn("Id").AsGuid().NotNullable().PrimaryKey().Identity()
.WithColumn("FirstName").AsString()
This results in a PK uuid which seems promising:
Create.Table("Players")
.WithColumn("Id").AsGuid().NotNullable().PrimaryKey().WithDefault(SystemMethods.NewSequentialId)
.WithColumn("FirstName").AsString()
however when I attempt the following query:
insert into "Players" VALUES ('George')
I get the following error
ERROR: invalid input syntax for type uuid: "George"
LINE 1: insert into "Players" VALUES ('George')
It seems then that I cannot have an auto generating uuid.
an int identity also doesnt work:
Create.Table("Players")
.WithColumn("Id").AsInt32().NotNullable().PrimaryKey().Identity()
.WithColumn("FirstName").AsString().NotNullable();
results in a primary key but not an identity column.
ERROR: invalid input syntax for type integer: "George"
LINE 1: insert into "Players" VALUES ('George')
Expected behavior An identity column should be generated
Information (please complete the following information):
- OS: [ Windows 10 ]
- Platform [.Net Core 5 / PostgreSQL 13]
- FluentMigrator version [ 3.2.15 ]
- FluentMigrator runner [ “in-process runner” ]
- Database Management System [ Postgres ]
- Database Management System Version [ “pgAdmin 4” ]
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
PostgreSQL unable to set existing column as IDENTITY
Just to clarify what the documentation says: Don't use serial. For new applications, identity columns should be used instead.
Read more >PostgreSQL Identity Column
This tutorial shows you how to use the GENERATED AS IDENTITY constraint to create the PostgreSQL identity column for a table.
Read more >PostgreSQL 10 identity columns explained
One common problem is that permissions for the sequence created by a serial column need to be managed separately:
Read more >Restarting identity columns in Postgresql
From version 10, using identity columns, there is no need to use the sequence name. That's nice. ALTER TABLE table ALTER COLUMN id...
Read more >PostgreSQL: Create Identity Column in a Table
In PostgreSQL, the identity column is a NOT NULL column that has an implicit sequence attached to it and the column in new...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@lillo42 can you please look
Im very sorry! Im sorry I wasted your time and thanks for the help. This was 10/10 stupid.