我创建了一个简单的表格:
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/