Skip to content

Magento 2: How to add two index for the same column in DB with db_schema.xml

I have a column name in my db_schema.xml, I want it to have the unique property and also fulltext, when I add these two fields it returns an error that said Index Name already exists, this is because Magento automatically assigns the name of the index as ” TABLE_NAME_COLUMN” in my case “TABLE_NAME_NAME”, is there any way to change the name assigned to the index from Magento? or how could I solve this validation.

Error:

SQLSTATE[42000]: Syntax error or access violation: 1061 Duplicate key
name ‘VENDOR_MODULE_CATEGORYRELATIONSHIP_NAME’, query was: ALTER TABLE
vendor_module_categoryrelationship ADD FULLTEXT INDEX
VENDOR_MODULE_CATEGORYRELATIONSHIP_NAME (name)

<column name="name" xsi:type="varchar" nullable="false" length="128" comment="Name of the category relationship"/>
<constraint xsi:type="unique" referenceId="VENDOR_MODULE_CATEGORYRELATIONSHIP_NAME">
    <column name="name"/>
</constraint>
<index indexType="fulltext" referenceId="VENDOR_MODULE_CATEGORYRELATIONSHIP_NAME_FULLTEXT">
    <column name="name"/>
</index>