CodeIgniter4
CodeIgniter4 copied to clipboard
_processForeignKeys | Identifier name is too long
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);
}
In the first place, why would you name your table and/or fields too long?
In the first place, why would you name your table and/or fields too long?
cause I can do it?
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.
Why more than 64 characters?
Why more than 64 characters?
Mysql Limit: https://dev.mysql.com/doc/refman/8.0/en/identifier-length.html
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:
- use of table prefixes chosen by the user.
- talkative developer
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
@sandrocantagallo
We support:
- MySQL (5.1+) via the MySQLi driver
- PostgreSQL via the Postgre driver
- SQLite3 via the SQLite3 driver
- MSSQL via the SQLSRV driver (version 2005 and above only)
And want to support Oracle #2487, too.
Might be related to #5075
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.
Oracle 12.1 is only 30 bytes.
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.