-
-
Notifications
You must be signed in to change notification settings - Fork 502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto generated index/foreign keys are sometimes too long #1271
Comments
You can specify the index name manually: @ManyToOne({ entity: () => SponsoredPageTemplate, index: 'custom_idx_name' }) But yes, there is currently no way to adjust the FK constraint name. |
Is it possible to update mikro-orm such that it generates identifiers that are always <64 chars? |
Sure we can make it work that way (i guess only in mysql, or is this a common limitation?). |
I got the Mysql limitations from their v5.7 docs, but I am not familiar with any other DB drivers so I am not sure how they handle this |
@B4nan I tried a quick fix locally which seems to work and put it in a PR - let me know what you think |
This is a problem in postgres too, https://www.postgresql.org/docs/12/limits.html says the identifier limit is 63 bytes. Should I file a new issue? On a related note, it seems sqlite has no identifier limit. I have no idea how things work with mongodb but it seems to have a limit of 120 bytes maybe? |
This is already fixed for postgres, see #1915 (probably in v5 only - no plans to backport anything schema related to v4). |
Describe the bug
When specifying related objects with @OneToMany or @manytoone, mikro-orm will automatically create relevant index and foreign key constraints with generated names based on entity names.
In some cases this means that we go past the 64 character limit for index/foreign key identifiers.
To Reproduce
Try an example like this
You will get the error below:
Stack trace
I am unfortunately unable to rename any of the entities or tables, so I am looking for a way to alter mikro-orm's behavior here.
Attempted fixes
I tried explicitly adding an index to the child entity like this
However then I hit the same issue for the automatically generated foreign key constraint:
Expected behavior
Mikro-orm should know when an identifier will violate the 64 character limit and come up with an alternative name, maybe something like this
<first few chars of entity A>_<first few chars of entity B>_<some random string to avoid duplication>
Versions
The text was updated successfully, but these errors were encountered: