sequelize 无法识别 table 名称

sequelize not recognizing table name

我的要求不是 define/alter table 来自 Sequelize 的定义。所以,我没有打电话给 await sequelize.sync();

但是,问题在于 Sequelize 无法识别 table,而是使用双引号触发查询。我将相同的查询从控制台复制到 pgadmin 并且它不能使用双引号,但是当它们被删除时,它可以工作。我不确定我们是否需要进行任何配置更改。

SELECT "id" AS "userId", "name" FROM "schema.table_name" AS "tableAlias" WHERE "tableAlias"."name"

异常:

[Nest] 22364  - 03/21/2022, 6:22:21 PM   ERROR [ExceptionsHandler] relation "schema.table_name" does not exist

模型定义:

@Table({
  timestamps: false,
  freezeTableName: true,
  tableName: "schema.table_name"
})

    export class TableAlias  extends Model<TableAlias>{
    
      @PrimaryKey
      @Column({
       field: 'id'
        })
       userId: number;
    
      
       @Column({field: 'name'})
        name: number;
    }

您不应将 table 名称与架构一起指定。请在schema选项中单独注明:

@Table({
  timestamps: false,
  freezeTableName: true,
  tableName: "table_name",
  schema: "schema"
})

    export class TableAlias  extends Model<TableAlias>{
    
      @PrimaryKey
      @Column({
       field: 'id'
        })
       userId: number;
    
      
       @Column({field: 'name'})
        name: number;
    }