Default value is not escaped when using enum, which cause error: cannot use column reference in DEFAULT expression
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
I have simple migration.
import {
MigrationInterface,
QueryRunner,
Table,
} from 'typeorm';
export class CreateExampleable1578929385472 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(new Table({
name: 'example',
columns: [
{
name: 'id',
type: 'int',
isPrimary: true,
isGenerated: true,
},
{
name: 'enum',
type: 'enum',
enum: ['A', 'B', 'C'],
default: 'A',
},
],
}));
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('example');
}
}
I am getting error: QueryFailedError: cannot use column reference in DEFAULT expression
SQL which cause issue:
CREATE TABLE example(... "status" "example_enum_enum" NOT NULL DEFAULT A ... )
It should quote default value:
CREATE TABLE example(... "enum" "example_enum_enum" NOT NULL DEFAULT 'A' ... )
I had to quote default value my self to make it work:
(Without whitespaces, whitespaces added, to make it visible)
default: " 'A' "
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:9
Top GitHub Comments
The @agoulziprod 's solution don’t work to me. But that works:
I had a similar error when adding a column with a default value, no db-level enum involved:
(quoted from https://github.com/typeorm/typeorm/issues/2980)