Hallo Zusammen,
Ich habe über ein Plugin mehrere eigene Repositories angelegt inkl. Entity, Definition und Collection Klasse.
Eines der Repositories (EsiMapping) soll nun per FkField auf ein zweites durch mich angelegtes Repository (EsiAttributeValues) referenzieren.
Beim Installieren kriege ich nun einen „General error: 1215 Cannot add foreign key constraint“.
EsiAttributeValuesDefinition.php (Das Repository auf das referenziert werden soll):
protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required()),
(new IntField('configuration_id', 'configurationId'))->addFlags(new Required()),
(new IntField('eevo_id', 'eevoId'))->addFlags(new Required()),
(new StringField('eevo_label', 'eevoLabel'))->addFlags(new Required())
]);
}
EsiMappingDefinition.php (Das Repository, welches auf EsiAttributeValues per FkField verweisen soll):
protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required()),
(new IntField('configuration_id', 'configurationId'))->addFlags(new Required()),
(new FkField('eevo_id', 'eevoId', EsiAttributeValuesDefinition::class))->addFlags(new Required()),
(new StringField('eevo_label', 'eevoLabel'))->addFlags(new Required()),
(new IdField('shop_id', 'shopId'))->addFlags(new Required()),
(new StringField('shop_label', 'shopLabel'))->addFlags(new Required()),
new IntField('position', 'position'),
new ManyToOneAssociationField('eevo', 'eevo_id', EsiAttributeValuesDefinition::class)
]);
}
Meine SQL Statements, um die Tabellen in de Migrations zu erzeugen sehen wie folgt aus:
MigrationEsiAttributeValues :
CREATE TABLE IF NOT EXISTS `esi_attribute_values` (
`id` BINARY(16) NOT NULL,
`configuration_id` INT(11) NOT NULL,
`eevo_id` INT(11) NOT NULL,
`eevo_label` VARCHAR(255) NOT NULL,
`created_at` DATETIME(3) NOT NULL,
`updated_at` DATETIME(3) NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
MigrationEsiMapping :
CREATE TABLE IF NOT EXISTS `esi_mapping` (
`id` BINARY(16) NOT NULL,
`configuration_id` INT(11) NOT NULL,
`eevo_id` BINARY(16) NOT NULL,
`eevo_label` VARCHAR(255) NOT NULL,
`shop_id` BINARY(16) NULL,
`shop_label` VARCHAR(255) NOT NULL,
`position` INT(11) NULL,
`created_at` DATETIME(3) NOT NULL,
`updated_at` DATETIME(3) NULL,
PRIMARY KEY (`id`),
KEY `fk.esi_mapping.eevo_id` (`eevo_id`),
CONSTRAINT `fk.esi_mapping.eevo_id` FOREIGN KEY (`eevo_id`) REFERENCES `esi_attribute_values` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Hat jemand eine Lösung? Ein Foreign Key auf die Shopware-eigene UserDefinition funktioniert problemlos.
Viele Grüße
Dennis