Typeorm generating migrations even though there is not any change in models
See original GitHub issueIssue 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
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:
- Created 2 years ago
- Reactions:2
- Comments:10 (2 by maintainers)
Top GitHub Comments
@lflfm Thank u man, setting
default:false
solves the issueSorry, 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 aboolean
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 })