addColumn in migration does not work as expected
See original GitHub issueIssue type:
[x] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[x] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.8
I have a migration to add a new column to an existing table (with data in it) using the following code:
async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.addColumn('myTable', new TableColumn({
name: 'my_new_column_name',
type: 'varchar',
isNullable: true
});
}
My expectation was that this code would be transformed to an ALTER TABLE
query in the background. When logging all database activity, I saw it actually tried to create a temporary table and drop the actual table. This seems weird to me and it also gave me an error because there was already a foreign key constraint on another column in this table. So the migration didn’t work. I fixed it by manually putting in an ALTER TABLE
query, but shouldn’t addColumn
already do that?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:5
I was able to fix a similar issue (on postgres) by wrapping my default value in single quotes:
Previously I was getting the error
column "open" does not exist
:This is downright baffling behavior.
@lili21 As I said in the last line: I fixed it by manually putting in an
ALTER TABLE
query, […]So not a real structural fix, but at least I got it working.