node.js - 查询失败错误 : the column "price" contain null values - TypeORM - PostgreSQL

标签 node.js postgresql typescript typeorm

我创建了一个简单的表格:

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

@Entity()
export class Test {
    @PrimaryGeneratedColumn()
    public id!: number

    @Column({ nullable: false })
    public name!: string

    @Column({ nullable: false, type: "float" })
    public price!: number
}

我生成迁移并运行它。当我在数据库中没有数据并且运行服务器时它成功了。但是当我在数据库中添加 1 行并再次运行它时,出现以下错误:

QueryFailedError:«price» 列包含空值

数据库定义了包含所有数据的行。我尝试了很多案例,但没有一个是正确的。

有人对此有想法吗?

最佳答案

我有一个类似的问题,我在 this thread 的底部报告了它.

您的 ORM 配置可能有 synchronize: true。因此,每次您运行应用程序时,Typeorm 都会尝试创建表格。如果您的数据库中有数据,它会引发误导性错误。

来自 here :

synchronize - Indicates if database schema should be auto created on every application launch. Be careful with this option and don't use this in production - otherwise you can lose production data. This option is useful during debug and development. As an alternative to it, you can use CLI and run schema:sync command. Note that for MongoDB database it does not create schema, because MongoDB is schemaless. Instead, it syncs just by creating indices.

关于node.js - 查询失败错误 : the column "price" contain null values - TypeORM - PostgreSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52064130/

相关文章:

ruby-on-rails - 计算月份统计

sql - 从父行获取子行数据

jquery - 将 JQuery 合并到 Typescript VS 2013 中

node.js - 另一条 route 未定义的快速 session

javascript - 将一个提供程序注入(inject)另一个提供程序,相同的模块 #1250

javascript - 我是否必须在 nodejs 中的每个回调之后检查错误?

javascript - 如何从 Node api 中的获取请求中解码 JWT token

javascript - 如何创建用户定义的类型(ala C#)以在 JavaScript 中的对象中使用?

postgresql - 通过二维数组列的第二个维度中的值查询表

reactjs - ApolloClient 类型错误 ApolloLink