How `typeorm migration:generate` command know that I am renaming a column?

Viewed 1196

In typeorm, if I rename an entity's column from:

@Column()
address: string

to

@Column()
userAddress: string

Does it know that I am renaming a column when I run the command

typeorm migration:generate?

Will I lose any data when I run the migration?

2 Answers

Just for the sake if other people should visit the question at some point. (I realize it's a old question)

TypeORM does NOT recognize it, and will try to drop the columns with data and create a new one. Often this poses conflicts if it the column is not nullable or worse drop tons of data silently.

Make sure to either configure the migration generated or write your own in this case.

The command migrations:generate will go over the entities files provided in the configurations file, and will make a new migrations file with the changes made for you. So, if you run this command after every change made, you wont lose data. Ofcourse that if you drop columns/tables you will lose its data because you delete it.

Make sure to have all the paths in the 'entities' paths array of the typeorm.config file

Related