In earlier TYPO3 versions it could happen that MM entries were created twice. This command singularises the existing MM entries and ensures that MM entries are unique.
If you either execute the command
typo3 database:updateschema
or perform a DB comparison under ‘Analyse Database Structure’ in the Admin Tools, and receive an Duplicate entry 'xxx-xxx' for key 'PRIMARY'
error message, then you are affected.
Error Message Example:
The following errors occurred:
+------------+--------------------------------------------------------+-----------------------------+
| Type | SQL Statement | Message |
+------------+--------------------------------------------------------+-----------------------------+
| Add fields | ALTER TABLE | Duplicate entry '108-349' |
| | `tx_lccontact_contact_fieldworkerpostalcodes_postalcod | for key 'PRIMARY' |
| | e_mm` ADD PRIMARY KEY (uid_local, uid_foreign) | |
| | | |
| | ALTER TABLE | Duplicate entry '0-106' for |
| | `tx_lccontact_contact_fieldworkercountryfallback_count | key 'PRIMARY' |
| | rygroup_mm` ADD PRIMARY KEY (uid_local, uid_foreign) | |
| | | |
| | ALTER TABLE `sys_category_record_mm` ADD PRIMARY KEY | Duplicate entry |
| | (uid_local, uid_foreign, tablenames, fieldname) | '23-83-tx_news_domain_model |
| | | _news-categories' for key |
| | | 'PRIMARY' |
| | | |
+------------+--------------------------------------------------------+-----------------------------+
Place this script under EXT:sitepackage/Classes/Command/FixMmDuplicatesCommand.php
and adjust the namespace specification if necessary.
As this process is a database update, it must be performed before the upgrade wizards are executed. Accordingly, this is a command that can be executed by
typo3 upgrade:fixmmduplicates
Please note that this command sets the fields sorting
and sorting_foreign
to the value 0
. If you have a better solution for these fields, you are welcome to contribute it here.