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.

Typeorm generating migrations even though there is not any change in models

See original GitHub issue

Issue Description

i created a passenger.entity.ts file added few fields over it. Then i generated a migration named first and i run migration run command successfully and then i can feel changes to my PostgreSQL database,

after few minutes, again i generated a migration named second,

here i am surprised to see that the second migration even generate the same SQL query as of first migrations.

Expected Behavior

i believe when i run command to generated second migration, it should show "typeORM No changes in database schema were found - cannot generate a migration. To create a new empty migration use “typeorm migration:create” command "

Actual Behavior

when i run first migration, following code is generated:

import {MigrationInterface, QueryRunner} from "typeorm";

export class first1627232991461 implements MigrationInterface {
    name = 'first1627232991461'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "passengers" ALTER COLUMN "is_deleted" SET DEFAULT 'false'`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "passengers" ALTER COLUMN "is_deleted" SET DEFAULT false`);
    }

}

when i run second migration command, following code is genetated:

import {MigrationInterface, QueryRunner} from "typeorm";

export class second1627234626276 implements MigrationInterface {
    name = 'second1627234626276'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "passengers" ALTER COLUMN "is_deleted" SET DEFAULT 'false'`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "passengers" ALTER COLUMN "is_deleted" SET DEFAULT false`);
    }

}

Surprisingly in both case there is same sql query

Steps to Reproduce

name of my column is inside .entity.ts file is:

@Column({ name: 'is_deleted', type: 'boolean', default: 'false' })
public isDeleted: boolean;

My Environment

Dependency Version
Operating System Ubuntu 20.04
Node.js version 14.16.1
Typescript version 4…2.4
TypeORM version 0.2.32

Additional Context

i believe following image clearly show this issue

image

Relevant Database Driver(s)

DB Type Reproducible
postgres yes

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️ Yes, I have the time, and I know how to start.
  • ✅ Yes, I have the time, but I don’t know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
chandrashekhar07commented, Aug 23, 2021

@lflfm Thank u man, setting default:false solves the issue

0reactions
lflfmcommented, Aug 23, 2021

Sorry, I hadn’t read the command completely. The only thing I notice now then is that the migrate up is trying to set default to a string that says 'false' while the migrate down sets the default to a boolean false. Maybe that’s the issue? Have you tried to set the default as a boolean in your model? instead of: @Column({ name: 'is_deleted', type: 'boolean', default: 'false' }) try: @Column({ name: 'is_deleted', type: 'boolean', default: false })

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - typeORM No changes in database schema were found
typeORM No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" ...
Read more >
Migrations - typeorm - GitBook
A migration is just a single file with sql queries to update a database schema and apply new changes to an existing database....
Read more >
TypeORM Migrations Explained - Better Programming
A migration in TypeORM is a single file with SQL queries to update a database schema. This is important to know as a...
Read more >
Migrations Over Synchronize in TypeORM | by Uthpala Pitawela
Migrations in TypeORM​​ Even Though synchronization is a good option to synchronize your entity with the database, it is unsafe for production databases. ......
Read more >
How to migrate from TypeORM to Prisma
Introspect your database; Install Prisma Client; Gradually replace your TypeORM queries with Prisma Client. These steps apply, no matter if you're building a...
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