typeorm: Update to 0.2.5 breaking things

Issue type:

[X ] question [ ] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [X ] postgres [ ] sqlite [ ] sqljs [ ] react-native

TypeORM version:

[ X] latest [ ] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (2 by maintainers)

Most upvoted comments

@RDeluxe I had the same error popping up when the data in the tables looked perfect. Your comment about the query actually trying to create the column helped me find the issue. Do you have synchronize: true in your ormconfig.json? If so, every time you run the app typeorm tries to recreate the tables and since you have data in there, throws that misleading error. @pleerock should I report it as an issue?

Same problem here.

To solve this issue, delete the entire dist folder and try again. Hopefully it works for you as well. Let us know if this did the trick.

Not sure if I should be opening a new issue or ask to reopen this one, I’m encountering the same behavior.

import { Entity, Column, PrimaryGeneratedColumn, BaseEntity } from 'typeorm';
import * as slug from 'slug';

@Entity()
export class SkillTagEntity extends BaseEntity {
  @PrimaryGeneratedColumn('uuid') 
  public id: string;
  
  @Column('varchar', { unique: true })
  public slug: string;
  
  @Column('varchar') 
   private name: string;

  @Column('timestamp', { nullable: true })
  public deleteDate?: Date;
}

The error :

ERROR:  column "slug" contains null values
STATEMENT:  ALTER TABLE "skill_tag" ADD "slug" character varying NOT NULL
column "slug" contains null values
QueryFailedError: column "slug" contains null values

Thing is, I have no null value in the column “slug”, not do I have duplicates. I checked the existence of duplicates with the following command :

select * from skill_tag tag
where (select count(*) from skill_tag inr
where inr.slug = tag.slug) > 1

Seems to me that the combo NOT NULL + UNIQUE, which is preventing us to use a default value, is causing this bug.

Edit : it seems that it’s trying to add the column instead of altering it ? But the error does not concur

What’s up with this issue now? it’s still happening. I got a table with data called categories there’s no null data in it in none of the columns, it says:

      [Nest] 11761  - 02/26/2023, 1:46:04 PM   ERROR [ExceptionHandler] column "name" of relation "categories" contains null values
      QueryFailedError: column "name" of relation "categories" contains null values

I tried doing this in the category.entity class:

     @Column({ nullable: true })
      name: string;

It auto updated all name strings to NULL, stupid feature isn’t it? Setting syncronize: false is solving it, but in production won’t it throw the same error when matching the entity to table with content? Also, why shall we turn off syncronization if that feature is there?

I had the same bug, when I was going to add a column in the “user” table the solution was to warn that initially the column will be null, unfortunately I could not add a fixed value when creating it, as it generated some errors. Here’s the example that worked for me:

import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";

export class addColumnMotivationTableUser1675347094874
  implements MigrationInterface
{
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.addColumn(
      "user",
      new TableColumn({
        name: "motivation",
        type: "varchar",
        isNullable: true,
      })
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropColumn("user", "motivation");
  }
}

I had this issue and it can be fixed indeed as the community mentioned by setting Synchronize: false but also it can happen if you try to save data that has any type of relationship before saving its corresponding relation. e.g: Category and Question, one question has multiple categories so you try to save the question without saving first the categories if they don’t exist already in the database.

Same problem here.

@younusmahmood

Please re-open the issue, because it seems that the devs here don’t take this issue serious. I am having the same problem with @Alain1405 @RDeluxe.