Reputation: 659
I'm trying to modify a TypeOrm migration script, already running perfectly with MySQL, to work with PostgreSQL.
I got stuck on some table creation with a generated column:
{
name: 'id',
type: 'varchar',
isPrimary: true,
isGenerated: true,
generationStrategy: 'uuid',
}
Not sure why, but I get the following syntax (I left out the working parts):
CREATE TABLE "my_table_name" ("id" NOT NULL DEFAULT uuid_generate_v4(), <some other fields> , CONSTRAINT "<pk>" PRIMARY KEY ("id"))
The migration throws the following error: error: syntax error at or near "NOT"
, which I narrowed down to the obvious problem of no type declaration between "id"
and NOT
If I remove the isGenerated
from the config, the type appears and everything works but without the DEAFAULT uuid_generate_v4
part.
I'm not sure what could be the problem, and I'd appreciate your help
Thnx!
Upvotes: 2
Views: 1262
Reputation: 31
Your id type must be 'uuid' to match generation strategy, like this:
{
name: 'id',
type: 'uuid',
isPrimary: true,
isGenerated: true,
generationStrategy: 'uuid',
}
Upvotes: 3
Reputation: 566
When we use MYSQL we need to know that does not exist NOT NULL
, exist IS NOT NULL
.
So your code will be
CREATE TABLE "my_table_name" ("id" IS NOT NULL DEFAULT uuid_generate_v4(), <some other fields> , CONSTRAINT "<pk>" PRIMARY KEY ("id"))
.
Upvotes: 0