Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js nestjs获取错误的Typeorm:语法错误在或接近;不是";当我运行迁移时_Node.js_Typescript_Nestjs_Typeorm - Fatal编程技术网

Node.js nestjs获取错误的Typeorm:语法错误在或接近;不是";当我运行迁移时

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

您好,我正在使用nest js的typeorm。一切正常。迁移是按照我的要求创建的,但是当我试图使一个列的主键为uuid时,出现了一个问题 这是密码

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";