I've created a simple table:
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
}
I generate the migration and run it also. When I have no data in the database and I run the server it succeed. But when I add 1 row in the database and I run it again it appears the following error:
QueryFailedError: the column «price» contain null values
The databse definetely has the row with all the data. I tried a lot of cases and none of them was correct.
Has anybody some idea for it?
I had a similar issue, and I reported it at the bottom of this thread.
You probably have synchronize: true
on your ORM configuration. Because of this, every time you run your app Typeorm tries to create the tables. If you have data in your DB, it throws that misleading error.
From 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.