Reputation: 61
I am trying to set the default value of a column as 'Canada/Eastern' and set it to not null. Here is what the column looks like:
queryRunner.addColumn('users', new TableColumn({
name: 'timezone_name',
type: 'character varying',
default: '"Canada/Eastern"',
isNullable: false,
}));
Its giving me an error:
query failed: ALTER TABLE "users" ADD "timezone_name" character varying NOT NULL DEFAULT "Canada/Eastern"
error: error: column "Canada/Eastern" does not exist
Upvotes: 0
Views: 9787
Reputation: 1
Remove isNullable and Try below code
queryRunner.addColumn('users', new TableColumn({
name: 'timezone_name',
type: 'character varying',
default: '"Canada/Eastern"'
}));
Upvotes: 0
Reputation: 61
Using "'Canada/Eastern'" fixes the error
queryRunner.addColumn('users', new TableColumn({
name: 'timezone_name',
type: 'character varying',
default: "'Canada/Eastern'",
isNullable: false,
}));
Upvotes: 5