Node.js nestjs获取错误的Typeorm:语法错误在或接近;不是";当我运行迁移时
您好,我正在使用nest js的typeorm。一切正常。迁移是按照我的要求创建的,但是当我试图使一个列的主键为uuid时,出现了一个问题 这是密码Node.js nestjs获取错误的Typeorm:语法错误在或接近;不是";当我运行迁移时,node.js,typescript,nestjs,typeorm,Node.js,Typescript,Nestjs,Typeorm,您好,我正在使用nest js的typeorm。一切正常。迁移是按照我的要求创建的,但是当我试图使一个列的主键为uuid时,出现了一个问题 这是密码 import {MigrationInterface, QueryRunner, Table} from "typeorm"; export class StudentsResponseTable1616216067510 implements MigrationInterface { public async up
import {MigrationInterface, QueryRunner, Table} from "typeorm";
export class StudentsResponseTable1616216067510 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(new Table({
name: 'students',
columns: [
{
name: 'id',
type: 'varchar',
isGenerated: true,
generationStrategy: 'uuid',
isPrimary: true
},
{
name: 'feedback',
type: 'jsonb',
}
]
}))
}
public async down(queryRunner: QueryRunner): Promise<void> {
}
}
感谢您花时间提供解决方案如果您想使用
生成策略:“uuid”
列类型必须是“uuid”
。不幸的是,网上有一些过时的信息,说明你应该使用'varchar'
。这是错误的:您需要'uuid'
此外,如果尚未执行此操作,则必须在数据库上运行以下命令才能使用uuid生成策略:
CREATE EXTENSION "uuid-ossp";
我正在使用typeorm,当我从
varchar
更改为uuid
时,用户表将成功迁移。但是,当我将外键应用到引用它的另一个表时,我收到了错误。所以我从columnType uuid
切换回varchar
CREATE EXTENSION "uuid-ossp";