I have a custom component with a long table file name for categories. Eg.: com_portal_transicao.transicaoregulacoes.category.271
Save categories without errors
I got this error message:
1062 Duplicate entry 'com_portal_transicao.transicaoregulacoes.category.' for key '#__assets.idx_asset_name'
PHP 8.3
Mysql 8
Joomla 3
Joomla 4
Joomla 5
Please provide a long VARCHAR for this column: name in the assets table.
The ideal length is 255 in both "name" and "title" columns. I suggest because this is the default Joomla Article
Thanks, for advance! I trust in the Joomla team!
Labels |
Added:
No Code Attached Yet
|
Labels |
Added:
Information Required
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2024-01-19 14:46:59 |
Closed_By | ⇒ | richard67 |
Status | Closed | ⇒ | New |
Closed_Date | 2024-01-19 14:46:59 | ⇒ | |
Closed_By | richard67 | ⇒ |
Labels |
Added:
bug
Removed: Information Required |
Hmm, 100 will not be enough.
The asset names for categories are determined by the Category table class here: https://github.com/joomla/joomla-cms/blob/5.0-dev/libraries/src/Table/Category.php#L290 .
The $this->extension
comes from the name
column of the #__extensions
table. That can have a length of max. 100.
Then ".category" is appended, so we have max. 109 characters.
Finally, ".<id>
" is appended, with <id>
being the category ID. That can have a length of up to 10 characters (signed or unsigned integers on MySQL or MariaDB or PostgreSQL databases).
So we need a max. length of 120 characters for the asset names of categories.
But this is only for categories.
We have other asset types like e.g. "com_modules.module.<id>
" for module or "com_content.transition.1" for workflow transitions. The length of that middle part "category" or "module" or "transition" is not really limited anywhere.
We have another table #__content_types
which uses type aliases which are created in a similar way, just that there is no ".<id>
" appended at the end. That table's type_alias
column has max. 400 characters. If we wanted to be consistent with that, we would need max. 411 characters due to the appended ".<id>
".
On Joomla 4 which has to support MySQL < 5.7 and MariaDB < 10.2 the maximum key length was 767 bytes, which means for utf8mb4 max. 191 characters, so the unique key would have been limited to the first 191 characters only, so a length of asset names greater than that would not really have worked.
But on Joomla 5 we require database versions which support a max. key length of 3072 bytes, which would be max. 768 characters with utf8mb4. So a max. length of 411 would work here, but the question is if we really want it to be that big.
We could forget about that #__content_types
table and say we assume that the middle part of the asset name can be max. 20 characters like it is with the type
column in the extensions table. Then we would have max. 132 characters for the complete asset name.
What do others think? Opinions please.
Thanks for the analysis @richard67 I am wondering why we have never come across this before
I am wondering why we have never come across this before
@brianteeman That can only have been lucky circumstances.
I can guess it was made to save memory, or speed up query, or something like that. Because this table is extensively in use.
I had this isue in past in one of my custom component, and just hacked the __asset table by install script ?
$db = Factory::getDbo();
$assetTable = $db->replacePrefix('#__assets');
$query = 'SELECT CHARACTER_MAXIMUM_LENGTH FROM information_schema.columns'
.' WHERE table_schema = DATABASE() AND table_name = ' . $db->q($assetTable) . ' AND COLUMN_NAME = ' . $db->q('name');
$result = (int) $db->setQuery($query)->loadResult();
if ($result < 80) {
$query = 'ALTER TABLE ' . $assetTable . ' MODIFY ' . $db->qn('name') . ' VARCHAR(80)';
$db->setQuery($query)->execute();
}
I not sure what length is good or enough here, but could assume that the column should contain only UTF-8 latin symbols (non utf8mb4), and allow default 255.
@Fedik If we want to fix this issue also in 4.4-dev we are limited to max. 191 characters due to the max. key size. In 5.x-dev we don't have this limitation due to the database requirements of J5. So it's the question if it's a bug fix or a new feature, and in case of bug fix if we want to fix it in 4.4, too.
Personally I tend to not fix it in 4.4-dev because it would need an update SQL for 4.4.x and another one in the 5.x-dev branches for 5.0.x to cater for all possible update scenarios.
To me 5.x is fine. What others will say.
Title |
|
I will create a pull request on weekend.
The ideal length is 255 in both "name" and "title" columns. I suggest because this is the default Joomla Article
@uzielweb As I explained in my comment above, we cannot use 255 for the "name" column as there is a unique index on it and the maximum index lengths on MySQL < 5.7 and MariaDB < 10.2 is 191 characters, and Joomla 4 still has to support these database versions. So your statement in the description about ideal length is not right.
All right, but we need this in Joomla 5, MYSQL 8, as ideal.
Sorry for my late comment about this.
Duplicate #42283?