小编Rya*_*all的帖子

使用 NestJS 和 TypeOrm,在运行 NestJS 应用程序后不会自动创建表

使用 postgres 数据库,我能够连接到数据库,但是即使按照教程一步一步,在创建 user.entity.ts 文件(下面的代码)后,数据库中没有任何变化。

据我所知,最新版本的 postgres/typeorm 已正确安装。

import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm'

@Entity()
export class Users {

    @PrimaryGeneratedColumn('uuid')
    id: number

    @Column({
        length: 50
    })
    firstName: string;
}
Run Code Online (Sandbox Code Playgroud)

这是 ormconfig.json

{
    "type": "postgres",
    "host": "localhost",
    "port": "5432",
    "username": "postgres",
    "password": "pw",
    "database": "metabook",
    "synchronise": true,
    "logging": true,
    "entities": ["./dist/**/*.entity{.ts,.js}"]
}
Run Code Online (Sandbox Code Playgroud)

它应该添加带有 2 列(id 和 firstName)的“用户”表。在控制台中,日志记录(在 ormconfig.json 中设置为 true)应该显示正在运行的 sql 查询以创建表,但除了成功运行应用程序(下面的输出)之外没有任何其他反应。

输出

教程视频的预期输出

有谁知道我是否遗漏了什么?

postgresql config typescript typeorm nestjs

1
推荐指数
1
解决办法
2589
查看次数

标签 统计

config ×1

nestjs ×1

postgresql ×1

typeorm ×1

typescript ×1