Generated Columns Not Compatible with PSQL 9.x
See original GitHub issueGetting an error on generating some Identity Framework tables:
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
Failed executing DbCommand (14ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE "AspNetRoleClaims" (
"Id" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"RoleId" uuid NOT NULL,
"ClaimType" text NULL,
"ClaimValue" text NULL,
CONSTRAINT "PK_AspNetRoleClaims" PRIMARY KEY ("Id"),
CONSTRAINT "FK_AspNetRoleClaims_Roles_RoleId" FOREIGN KEY ("RoleId") REFERENCES "Roles" ("Id") ON DELETE CASCADE
);
Npgsql.PostgresException (0x80004005): 42601: syntax error at or near "GENERATED"
at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 1032
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming) in C:\projects\npgsql\src\Npgsql\NpgsqlDataReader.cs:line 444
at Npgsql.NpgsqlDataReader.NextResult() in C:\projects\npgsql\src\Npgsql\NpgsqlDataReader.cs:line 332
at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken) in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 1219
at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken) in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 1042
at Npgsql.NpgsqlCommand.ExecuteNonQuery() in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 1025
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
[... my app here]
As far as I can tell, the GENERATED
keyword isn’t valid on Postgres 9.x, that’s a thing in 10.x. I’d just upgrade but Google Cloud SQL only supports 9.6…
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Documentation: 15: 5.3. Generated Columns
A generated column is a special column that is always computed from other columns. Thus, it is for columns what a view is...
Read more >sql - Does PostgreSQL only support STORED generated ...
The documentation clearly states that virtual generated columns are not supported. PostgreSQL currently implements only stored generated columns ...
Read more >Thread: Generated column is not updated (Postgres 13)
- a generated column is never updated if you pass the whole record to a stored procedure (an immutable function);. - however, it...
Read more >How to pass the current row to Generated Column function ...
If it did work, it could only work by first creating the table, then the function, then adding the generated column. However, doing...
Read more >The Ultimate Guide to SQL Generated Columns
Generated columns are supported by many popular relational databases, including MySQL, MariaDB, PostgreSQL, SQL Server, and Oracle.
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 Free
Top 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
Duplicate of #681.
By default, the provider assumes that the backend is running the latest version of PostgreSQL. To opt out, you must explicitly configure the provider to use a specific version:
I’m closing this issue for now, but please give that a try and let us know if you have any further questions related to this issue.
You seem to be activating the IDENTITY columns feature, which was only introduced in PostgreSQL 10. Remove
ForNpgsqlUseIdentityColumns()
from your model or upgrade to a newer version of PostgreSQL.If the problem still persists, please post your model definition (especially your
OnModelCreating()
).