Open its-vincesanity opened 5 years ago
Same results with:
await queryRunner.renameColumn('audit_log', 'body', new TableColumn( {
name: 'body',
type: 'text',
isNullable: true
}));
and
await queryRunner.changeColumn('audit_log', 'body', new TableColumn( {
name: 'body',
type: 'text',
isNullable: true
}));
Both call
ALTER TABLE `audit_log` DROP COLUMN `body`
Is there any explanation about why data is lost?
@vincevaghalsen
Migrations just execute passed query, so those alter table statements are generated from somewhere else. Are you sure you don't have synchronize: true
set at the same time?
As for renameColumn and changeColumn: renameColumn was suposed to be data-safe, but it isn't if you pass TableColumn instead of a string. Tbh. I have no idea why there is a possibility of passing a TableColumn object here. Method name is rename column so only rename should be possible.
@pleerock @AlexMesser Can we change newTableColumnOrName: TableColumn|string
to newColumnName: string
? We have a major naming problem here. Current behavior is not data-safe while renameColumn was meant to be data-safe.
I make some tests, i have the same problem, so, i expect to be helpful:
version: mysql 5.6.44
On generate migration for alter a column, the migrations always generate a drop and create instead a change.
This comparison returns true, even without significant changes, so the drop is created.
Issue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]mongodb
[ ]mssql
[x]mysql
/mariadb
[ ]oracle
[ ]postgres
[ ]sqlite
[ ]sqljs
[ ]react-native
[ ]expo
TypeORM version:
[x]
latest
[ ]@next
[ ]0.x.x
(or put your version here)I wanted to migrate a column type from VARCHAR(255) to TEXT with:
Sometimes it works as expected and sometimes it drops the data from my column. So, I setup an audit log in my MySQL:
My logs say:
Why did it drop my table, I don't want lose my data If I change a column type :\