codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.4k stars 1.9k forks source link

_processForeignKeys | Identifier name is too long #5046

Closed sandrocantagallo closed 2 years ago

sandrocantagallo commented 3 years ago

Describe the bug using a table name and a fairly long column name exceeds the limit of 64 characters

CodeIgniter 4 version "codeigniter4/framework": "^4"

vendor\codeigniter4\framework\system\Database\Forge.php

protected function _processForeignKeys

Line: 1298 -> $nameIndex = $table . '_' . $field . '_foreign';

Possible Fix:

$lenght_nameIndex = strlen($nameIndex);

if ($lenght_nameIndex > 64) {
    $character_to_remove = $lenght_nameIndex-64;
    $nameIndex  = substr($nameIndex, $character_to_remove, 64);
}
paulbalandan commented 3 years ago

In the first place, why would you name your table and/or fields too long?

sandrocantagallo commented 3 years ago

In the first place, why would you name your table and/or fields too long?

cause I can do it?

paulbalandan commented 3 years ago

I'm not trying to be rude or something. I'm asking a genuine question. If there exists a limitation of 64 characters then developers should be wary of that and try to limit their wordings of their used DB identifiers.

kenjis commented 3 years ago

Why more than 64 characters?

sandrocantagallo commented 3 years ago

Why more than 64 characters?

Mysql Limit: https://dev.mysql.com/doc/refman/8.0/en/identifier-length.html

sandrocantagallo commented 3 years ago

I'm not trying to be rude or something. I'm asking a genuine question. If there exists a limitation of 64 characters then developers should be wary of that and try to limit their wordings of their used DB identifiers.

how the name of an index is generated by a method of a framework should check if the generated name is legal and possibly modify it to make it legal.

there are several reasons why the limit can be reached:

the truth is that the naming of an index is arbitrary regardless of how the table and the field are named

in many frameworks these names are not dynamically generated like on Forge but the developer can choose it.

Maybe that's the right way to go

kenjis commented 3 years ago

@sandrocantagallo
We support:

And want to support Oracle #2487, too.

najdanovicivan commented 3 years ago

Might be related to #5075

ytetsuro commented 3 years ago

Oracle 12.1 is only 30 characters. Therefore, if you want to put in a limit of 64 characters or not, I think it is preferable to do it per driver.

kenjis commented 3 years ago

Oracle 12.1 is only 30 bytes.

kenjis commented 2 years ago

This is not a bug. It is possible to specify an identifier that always exceeds the character limit. Also, in implementations such as how many characters are used from the beginning, there is a possibility that the keys will be duplicated.

5075 would resolve the issue.