typeorm: Enum type not working in postgres
Issue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
TypeORM version:
[x] latest
[ ] @next
[ ] 0.2.0 (or put your version here)
Steps to reproduce or a small repository showing the problem:
type Action =
'add' |
'update' |
'delete';
@Entity()
export class DatasourceAction {
@PrimaryColumn()
id: string;
@Column({ name: 'name', type: 'text', unique: true })
name: string;
@Column({ name: 'action', type: 'enum', enum: ['add', 'update', 'delete'] })
action: Action;
}
The SQL quarries executed are as follows
CREATE TYPE "test"."datasource_action_action_enum" AS ENUM('add', 'update', 'delete')
ALTER TABLE "test"."datasource_action" ADD "action" "datasource_action_action_enum" NOT NUL
and it errors with type “datasource_action_action_enum” does not exist
I think the the ALTER TABLE query should have been as follows. ALTER TABLE “test”.“datasource_action” ADD “action” “test”.“datasource_action_action_enum” NOT NUL
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 21
- Comments: 17 (9 by maintainers)
Links to this issue
Commits related to this issue
- Fix enum handling in non default namespace, fixes #1997 — committed to evik42/typeorm by evik42 6 years ago
- Fix enum handling in non default namespace, fixes #1997 — committed to evik42/typeorm by evik42 6 years ago
- Merge remote-tracking branch 'evik42/fix_issue_1997' * evik42/fix_issue_1997: extend test cases to cover all uses of enums Fix enum handling in non default namespace, fixes #1997 — committed to smonv/typeorm by deleted user 6 years ago
- Merge pull request #2746 from evik42/fix_issue_1997 Fix enum handling in non default namespace, fixes #1997 — committed to typeorm/typeorm by pleerock 6 years ago
- working "github issues > #1997 enum type not working in postgres when defined in a custom schema" — committed to typeorm/typeorm by bbakhrom 5 years ago
I hit the same problem
Gender enum class
@pleerock I added all the previous enum tests with external schema as part of the PR, I also used this by manually patching typeorm in prod, let me know how I can assist to move this forward.
this long-expected bug was fixed by @evik42 ! Will be released in
@rcsoon.RolesEnum.ts
User.ts entity
Worked for me as of version
^0.2.7FYIchanges were already published
May i know when could i see this issue fixed on master?
@pleerock planned to release 0.2.8 and merge some PR’s this weekend. Not sure if that will be merged today, but we’re planning to slowly merge them all.
@Kononnable what do I need to do to get my PR checked for this?
fwiw I’ve been using string enum with check constraint. It’s a lot more flexible than actual postgres enum, which creates whole new data types in postgres index and are really hard to manage (alter table, etc.)
And use it like so
This also seems to happen for enums mapped to integers when syncing the Entities to the database. I’m using TypeORM version 0.2.7.
For example, if we take the following enum:
Then add an enum type field with a default value to an Entity:
This leads to the following error:
If we adjust the default to the integer value:
We still get an error:
+1, hitting the same. I think the original poster is spot on. It doesn’t seem to be using the correct schema on the query.