question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong nullable QueryFail

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I create Entity and i create a record from Data Grip and when i start nestjs app i have error

Minimum reproduction code

https://github.com/PatrykKuniczak/memesChat/tree/liveChat

Steps to reproduce

npm i npm run start:dev

Expected behavior

Script start, when data in DB is right, compatibile with entity

Package

Other package

@nestjs/typeorm

NestJS version

9.0.0

Packages versions

[System Information]
OS Version     : Windows 10
NodeJS Version : v16.16.0
NPM Version    : 8.1.4 

[Nest CLI]
Nest CLI Version : 9.1.5

[Nest Platform Information]
platform-socket.io version : 9.2.1
platform-express version   : 9.2.1
mapped-types version       : 1.2.0
websockets version         : 9.2.1
schematics version         : 9.0.3
testing version            : 9.2.1
typeorm version            : 9.0.1
common version             : 9.2.1
config version             : 2.2.0
core version               : 9.2.1
cli version                : 9.1.5

Node.js version

16.16.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

https://github.com/PatrykKuniczak/Machine-Shop-Manager/tree/main/backend

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


@Entity('PersonalDatum')
export class PersonalDatum {
    @PrimaryGeneratedColumn()
    id: number;

    @Column({length: 50})
    name: string;

    @Column({length: 50})
    surname: string;

    @Column({length: 50})
    birthCity: string;

    @Column("timestamp with time zone")
    birthDate: Date;
}

image

image

“QueryFailedError: column “birthDate” of relation “PersonalDatum” contains null values”

I using Postgresql

I have the same issue in my next project

image

@Entity("User")
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 20 })
  clientId: string;

  @Column({ length: 60 , default: ""})
  name: string;
}

“QueryFailedError: column “clientId” of relation “User” contains null values”

Whole Error:

QueryFailedError: column "clientId" of relation "User" contains null values
    at PostgresQueryRunner.query (F:\Projects\memesChat\backend\src\driver\postgres\PostgresQueryRunner.ts:299:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at PostgresQueryRunner.executeQueries (F:\Projects\memesChat\backend\src\query-runner\BaseQueryRunner.ts:651:13)
    at PostgresQueryRunner.addColumn (F:\Projects\memesChat\backend\src\driver\postgres\PostgresQueryRunner.ts:1115:9)
    at PostgresQueryRunner.addColumns (F:\Projects\memesChat\backend\src\driver\postgres\PostgresQueryRunner.ts:1129:13)
    at RdbmsSchemaBuilder.addNewColumns (F:\Projects\memesChat\backend\src\schema-builder\RdbmsSchemaBuilder.ts:823:13)
    at RdbmsSchemaBuilder.executeSchemaSyncOperationsInProperOrder (F:\Projects\memesChat\backend\src\schema-builder\RdbmsSchemaBuilder.ts:226:9)
    at RdbmsSchemaBuilder.build (F:\Projects\memesChat\backend\src\schema-builder\RdbmsSchemaBuilder.ts:95:13)
    at DataSource.synchronize (F:\Projects\memesChat\backend\src\data-source\DataSource.ts:318:9)
    at DataSource.initialize (F:\Projects\memesChat\backend\src\data-source\DataSource.ts:256:43)

^C  at DataSource.synchronize (F:\Projects\memesChat\backend\src\data-source\DataSource.ts:318:9)

I’d try do it but still didn’t work:

  @Column({ length: 60 , nullable: true})
  name?: string;

That’s intresting

create table "User"
(
    id         serial
        constraint "PK_9862f679340fb2388436a5ab3e4"
            primary key,
    name       varchar(60) not null,
    "clientId" varchar(20) not null
);

alter table "User"
    owner to postgres;

“nullable” work wrong, intresting, that’s something wrong after last update

I set “nullable” to ‘false’ run, and for ‘true’ and DDL looks fine

name       varchar(60)

but error appear when i start script

column "clientId" of relation "User" contains null values         

image

I create issue in Typeorm repository, but my bad is I didn’t test it without Nest, yesterday i do it, and it’s work with pure Typeorm, that’s intresting, that’s must be something wrong with 9 version of @nestjs/typeorm. Because earlier i didn’t have error like that

That’s the issue what I’ve told: https://github.com/typeorm/typeorm/issues/9587

I copy and paste, everything but maybe it’s also helpful.

On reproduction code, i send a github with my second project, because it’s less code and relations, easier to test 😃 But my first project is on the first line

I open to send more details 😃

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
PatrykKuniczakcommented, Dec 13, 2022

@micalevisk let’s clone now, i done something wrong in code, clone again now 😃

1reaction
PatrykKuniczakcommented, Dec 13, 2022

The problem, is “solved” i generate new nestJs app, and copy my src, error didn’t occure anymore.

That’s crazy issue, IDN what’s wrong, computers is a big mistery 😃

Thanks @micalevisk for support 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

INCORRECT RESULTS FROM REFERENCING NULLABLE ...
A query might get incorrect results when it references a nullable column <col> that has check constraints in the form of <col>=<literal>. DB2...
Read more >
Exception: The null value cannot be assigned to a member ...
The ParentId column is a nullable int from a Sql Server database. In the case of the ParentId field being null in the...
Read more >
Resolve "HIVE_BAD_DATA: Error parsing field value for field ...
Why does my Amazon Athena query fail with the error "HIVE_BAD_DATA: Error parsing field value for field X: For input string: "12312845691""?
Read more >
Why does simple XML PATH query fail? - MSDN - Microsoft
I thought it might be due to NULLS in nullable columns, so I placed ISNULL() for those columns that are NULLable. Can anyone...
Read more >
Sets — EdgeQL | EdgeDB Docs
error : QueryError: set constructor has arguments of incompatible types 'std::str' ... In SQL databases null is a special value denoting the absence...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found