Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeORM migration:generate produces pointless migration changes #3441

Closed
vladimirmoushkov opened this issue Jan 17, 2019 · 8 comments
Closed

Comments

@vladimirmoushkov
Copy link

vladimirmoushkov commented Jan 17, 2019

Issue type:

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

Database system/driver:

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

TypeORM version:

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

Steps to reproduce or a small repository showing the problem:
Add an following entity to existing TypeORM projecT:

import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
import { User } from "./User";

@Entity()
export class Session {
    @PrimaryGeneratedColumn()
    public id: number;

    @ManyToOne(() => User)
    @JoinColumn()
    public user: User;

    @Column({type: "char", precision: 64, nullable: false})
    @Index({unique: true})
    public sessionId: string;

    @Column()
    public validTo: Date;

    @Column()
    public lastActive: Date;
 }

Generate a migration using:

ts-node ../../../node_modules/.bin/typeorm migration:generate -n AnyName

It will produce initial migration that contains Session table creation. Then run the migration as:

ts-node ../../../node_modules/.bin/typeorm migration:run

And then re-run the migration generation

ts-node ../../../node_modules/.bin/typeorm migration:generate -n AnyName2

Result of that will be migration that regenerates sessionId column. If the entity lacks precision specifier, and the above scenario is re-ran it will produce no second AnyName2 migration.

The issue is similar to these ones where the precision triggers non existing difference observation by the migration generator:
#1960
#2943

@vladimirmoushkov vladimirmoushkov changed the title migration:generate produces TypeORM migration:generate produces pointless migration changes Jan 17, 2019
@corocn
Copy link

corocn commented Jan 18, 2019

Same issue to me. "Date" column continues to generate migration files that have pointless alter sql command.

@hungneox
Copy link

Is there any news on this? I also have the same issue.

@volnyansky
Copy link

@hungneox I fixed it with @column({type:"datetime",precision:0})

@Kononnable
Copy link
Contributor

@vladimirmoushkov

Result of that will be migration that regenerates sessionId column.

You shouldn't use precision on char column. Precision property is intended only for some numeric types. You should set length property instead.

As for datetime and precision - it will be fixed in 0.3.0 after merging #3262

@wasims1
Copy link

wasims1 commented Apr 25, 2020

anyone knows how to solve this issue? i have the same problem and it's getting rediculous..

@stouch
Copy link

stouch commented Aug 28, 2020

Same problem here.

@spmsupun
Copy link

it's 2021 and it's still happening :(

@dilpazir-whizpool
Copy link

2022 and still happening.
Version using: 0.2.41 (latest)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants