【问题标题】:Using NestJS and TypeOrm, the tables are not being created automatically after I run the NestJS application使用 NestJS 和 TypeOrm,在我运行 NestJS 应用程序后不会自动创建表
【发布时间】:2019-12-27 04:19:08
【问题描述】:

使用 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;
}

这里是 ormconfig.json

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

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

Output

Expected output from tutorial video

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

【问题讨论】:

  • 我认为键值是synchronize 对吧?
  • 您完全正确。太习惯英式拼写了,谢谢指出!现在按预期工作

标签: postgresql typescript config nestjs typeorm


【解决方案1】:

正如@Jay McDoniel 指出的那样,同步应该拼写为 z 而不是 s...(同步)

【讨论】:

    猜你喜欢
    • 2021-05-16
    • 2021-04-23
    • 2020-12-20
    • 2021-04-28
    • 2021-11-27
    • 2021-09-13
    • 2020-12-14
    • 2022-06-18
    • 2020-12-09
    相关资源
    最近更新 更多