Migration keeps changing @CreateDateColumn/@UpdateDateColumn timestamp column to same definition
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.16
(or put your version here)
Steps to reproduce or a small repository showing the problem:
I have a bunch of tables with my create- and updateTimestamp columns defined as follows:
@CreateDateColumn({ type: 'timestamp', precision: null, default: () => 'CURRENT_TIMESTAMP' })
createTimestamp: Date;
@UpdateDateColumn({ type: 'timestamp', precision: null, default: () => 'CURRENT_TIMESTAMP' })
updateTimestamp: Date;
When I run migration:generate
, typeorm is repeatedly (even after running it) generating a migration file that changes the column definition to the same definition it already has. You can tell because the up
and down
methods do the exact same thing. I would expect the migration to be empty.
Example migration file
import {MigrationInterface, QueryRunner} from "typeorm";
export class TestTimestamps1555253092006 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query("ALTER TABLE `album` CHANGE `createTimestamp` `createTimestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP");
await queryRunner.query("ALTER TABLE `album` CHANGE `updateTimestamp` `updateTimestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP");
}
public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query("ALTER TABLE `album` CHANGE `updateTimestamp` `updateTimestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP");
await queryRunner.query("ALTER TABLE `album` CHANGE `createTimestamp` `createTimestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP");
}
}
I can work around it by defining my create- and updateTimestamp columns as follows
@Column('timestamp', {
default: () => 'CURRENT_TIMESTAMP',
})
createTimestamp: Date;
@Column('timestamp', {
default: () => 'CURRENT_TIMESTAMP',
onUpdate: 'CURRENT_TIMESTAMP',
})
updateTimestamp: Date;
But it’s a shame that it’s not working with the @CreateDateColumn
and @UpdateDateColumn
decorators.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:5 (1 by maintainers)
Top GitHub Comments
EDIT: Probably a duplicate of #2737.
Same problem, happens also with foreign keys.
same issue. also index .