-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Closed
Description
Issue type:
[x] bug report
Database system/driver:
[x] mysql / mariadb
TypeORM version:
[x] latest
[x] @next
Steps to reproduce or a small repository showing the problem:
Create an enum column with default value null
enum MyEnum {
valueA = 'valueA',
valueB = 'valueB',
}
@Entity()
export class Entity extends BaseEntity {
@Column({
type: 'enum',
enum: MyEnum,
nullable: true,
default: null,
})
field?: MyEnum;
}result
{
message: "Invalid default value for 'field'",
code: 'ER_INVALID_DEFAULT',
errno: 1067,
sqlState: '42000',
sqlMessage: "Invalid default value for 'field'",
name: 'QueryFailedError',
query: "ALTER TABLE `entity` CHANGE `field` `field` enum ('valueA', 'valueB') NULL DEFAULT 'null'",
parameters: []
}It should've generated query: "ALTER TABLE ``entity`` CHANGE ``field`` ``field`` enum ('valueA', 'valueB') NULL DEFAULT null",
Adding && defaultValue !== null seems to work
typeorm/src/driver/mysql/MysqlDriver.ts
Line 572 in e8eb98b
| if ((columnMetadata.type === "enum" || columnMetadata.type === "simple-enum") && defaultValue !== undefined) { |
Reactions are currently unavailable