javascript - How to set string default value of a column in TypeORM migration - Stack Overflow

I am trying to set the default value of a column as 'CanadaEastern' and set it to not null.

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

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
Share Improve this question asked Nov 2, 2020 at 8:51 Mehul ChaturvediMehul Chaturvedi 611 silver badge6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Using "'Canada/Eastern'" fixes the error

queryRunner.addColumn('users', new TableColumn({
    name: 'timezone_name',
    type: 'character varying',
    default: "'Canada/Eastern'",
    isNullable: false,
  }));

Remove isNullable and Try below code

queryRunner.addColumn('users', new TableColumn({
    name: 'timezone_name',
    type: 'character varying',
    default: '"Canada/Eastern"'
  }));

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744253567a4565284.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信