Columns with the type "enum" are not supported in the migration API
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)
Steps to reproduce or a small repository showing the problem:
When writing migrations by hand using the migration API to create a new table that has an enum column 3 things happen that shouldn’t:
- The generated SQL does not sets the column’s type to enum.
- Worse, it sets the column’s type to “[Tablename]_[column]_enum”.
- The “enum” TableColumnOptions parameter gets ignored.
A simple example:
// == The entity
export enum RatingType {
low = 'bad',
neutral = 'neutral',
good = 'good'
}
@Entity({ name: 'Ratings' })
export default class Rating extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id: string
@Column({ type: 'enum', enum: RatingType })
rating: RatingType
}
// == The migration
import { MigrationInterface, QueryRunner, Table } from 'typeorm'
export class CreateRatings1569818629816 implements MigrationInterface {
private ratingsTable = new Table({
name: 'Ratings',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
isGenerated: true,
generationStrategy: 'uuid',
},
{
name: 'rating',
type: 'enum',
enum: ['bad', 'neutral', 'good'],
isNullable: true
}
],
})
async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(this.ratingsTable, true)
}
async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable(this.ratingsTable)
}
}
The generated SQL looks like this:
CREATE TABLE "Ratings" (
"id" uuid NOT NULL DEFAULT uuid_generate_v4(),
"rating" "Ratings_rating_enum",
CONSTRAINT "PK_ee6436ff188c9bb00cc70fc447a" PRIMARY KEY ("id")
)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Postgres enum in TypeORM - Stack Overflow
enum column type is supported by postgres and mysql. There are various possible column definitions: Using typescript enums:.
Read more >Bug? Changing a column of table that has an enum type.
Hi, I'm trying to make a new migration for updating a table: Originally, it has: id, name, gender Gender is an ENUM, name...
Read more >MySQL 8.0 Reference Manual :: 11.3.5 The ENUM Type
An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column...
Read more >Documentation: 15: 8.7. Enumerated Types - PostgreSQL
Enumerated (enum) types are data types that comprise a static, ordered set of values. They are equivalent to the enum types supported in...
Read more >Prisma schema API (Reference)
Unsupported fields can be introspected with prisma db pull or created with Prisma Migrate or db push . Remarks. Fields with Unsupported types...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
this worked with me
Almost the same solution, but here with typeorm
0.2.30
andPostgres
as database, I fixed with this: