typeorm: Column of type "enum" throws missing properties error
Hello there!
Issue Description
The version of TypeORM was updated to the latest release, while starting up the NestJS server it started throwing this enum error. As of my understanding the required properties are in the decorator.
Expected Behavior
To start correctly the TypeOrmCoreModule
Actual Behavior
Error: Column "type" of Entity "StandardSet" is defined as enum, but missing "enum" or "enumName" properties.
Steps to Reproduce
This code worked in version 0.2.31, once it was upgraded to 0.2.32 this error started appearing.
enum StandardSetType {
AcademicStandard = 'AcademicStandard',
FoundationalKnowledge = 'FoundationalKnowledge',
AchievementDescriptor = 'AchievementDescriptor',
}
@Column('enum', { enum: StandardSetType, name: 'type' })
type: StandardSetType;
My Environment
| Dependency | Version |
|---|---|
| Operating System | Ubuntu |
| Node.js version | v14.15.5 |
| Typescript version | 3.9.9 |
| TypeORM version | 0.2.32 |
| NestJS | 7.6.13 |
| nestJS/TypeORM | 7.1.5 |
Additional Context
Relevant Database Driver(s)
-
aurora-data-api -
aurora-data-api-pg -
better-sqlite3 -
cockroachdb -
cordova -
expo -
mongodb -
mysql -
nativescript -
oracle -
postgres -
react-native -
sap -
sqlite -
sqlite-abstract -
sqljs -
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time, and I know how to start.
- Yes, I have the time, but I don’t know how to start. I would need guidance.
- No, I don’t have the time, although I believe I could do it if I had the time…
- No, I don’t have the time and I wouldn’t even know how to start.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 10
- Comments: 17 (3 by maintainers)
Commits related to this issue
- added test for #7541 — committed to typeorm/typeorm by AlexMesser 3 years ago
- updated test for #7541 — committed to typeorm/typeorm by AlexMesser 3 years ago
- fix: issues with custom enum name in Postgres (#7661) * fix #7614 * updated test for #7541 * added test for #7647 * fixed failing test * fixed failing test; fixed `enumName` renaming; ... — committed to typeorm/typeorm by AlexMesser 3 years ago
- downgrade TypeORM to v0.2.31 Because of https://github.com/typeorm/typeorm/issues/7541 (specifically, https://github.com/typeorm/typeorm/issues/7541#issuecomment-1046195424). — committed to Vizzuality/marxan-cloud by hotzevzl 2 years ago
- maintenance(dependencies): Workaround on typeorm enum potential bug Tries to workaround to an apparent bug in typeorm when trying to use an enum as a type for a column in more than one entity, by exp... — committed to Vizzuality/marxan-cloud by KevSanchez a year ago
- maintenance(dependencies): Workaround on typeorm enum potential bug Tries to workaround to an apparent bug in typeorm when trying to use an enum as a type for a column in more than one entity, by exp... — committed to Vizzuality/marxan-cloud by KevSanchez a year ago
I faced the problem and mine was all about circular dependency and load order. I had two files of my entities:
One of the solutions to move your enum into separate file. Maybe this will help someone
I could reproduce this issue, when the same enum was used by 2 different entities
Cannot replicate.
When opening an issue, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This boils down to ensuring your code that reproduces the problem follows the following guidelines:
Minimal
The more code there is to go through, the less likely people can find your problem. Streamline your example in one of two ways:
Don’t sacrifice clarity for brevity when creating a minimal example. Use consistent naming and indentation, and include code comments if needed. Use your code editor’s shortcut for formatting code.
Don’t include any passwords or credentials that must be kept secret.
Complete
Make sure all information necessary to reproduce the problem is included in the issue itself.
If the problem requires some code as well as some XML-based configuration, include code for both. The problem might not be in the code that you think it is in.
Use individual code blocks for each file or snippet you include. Provide a description for the purpose of each block.
DO NOT use images of code. Copy the actual text from your code editor, paste it into the issus, then format it as code. This helps others more easily read and test your code.
Reproducible
To help you solve your problem, others will need to verify that it exists.
Describe the problem. “It doesn’t work” isn’t descriptive enough to help people understand your problem. Instead, tell other readers what the expected behavior should be. Tell other readers what the exact wording of the error message is, and which line of code is producing it. Use a brief but descriptive summary of your problem as the title of your question.
Eliminate any issues that aren’t relevant to the problem. If your question isn’t about a compiler error, ensure that there are no compile-time errors.
Double-check that your example reproduces the problem! If you inadvertently fixed the problem while composing the example but didn’t test it again, you’d want to know that before asking someone else to help.
After switching typeorm version from 0.2.31 -> 0.2.45. i had case of getting error (but in large codebase):
TypeORMError: Column "x" of Entity "y" is defined as enum, but missing "enum" or "enumName" properties..In one of the comments it was mentioned that issue is in enum defined in one entity file, but used in some other entities (in other entity files). After extracting that enum in separate file, and adding
enumattribute inside @Column decorator, migrations were successfully executed.The only thing that fixed the issue for me was to extract the enum into a separate file.
I happen to use the
{ type: 'enum', enum: StandardSetType }syntax. Does that work for you?The problem still persist on version
0.2.31.If you try use an Enum from other Entity, he will throw the error
It worked for me, thanks!