shopware / docs

Shopware 6 developer docs
https://developer.shopware.com/
51 stars 256 forks source link

Non-working example in: Adding complex data to existing entities #1463

Closed flytomek closed 2 months ago

flytomek commented 2 months ago

I was following the example in the documentation and durning execution of migration, I got the following error:

Failed to add the foreign key constraint. Missing unique key for constraint 'fk.swag_example_extension.product_id' in the referenced table 'product'

I took closer look at the product table and realized, that the primary key of this table is not id, but id, version id.

So to make the documentation example working I had to do the following things:

  1. Add additional column in the migration SQL:
    `product_version_id` BINARY(16) NOT NULL,
  2. Modify foreign key in the migration SQL:
    CONSTRAINT `fk.swag_example_extension.product_id` FOREIGN KEY (`product_id`, `product_version_id`) REFERENCES `product` (`id`, `version_id`) ON DELETE CASCADE ON UPDATE CASCADE 
  3. Add additional field in the entity definition class:
    new ReferenceVersionField(ProductDefinition::class, "product_version_id"),
Isengo1989 commented 2 months ago

@flytomek thx for creating the issue. I was following along the post in slack (recognizable with the :eye: ) - but appreciated anyways :+1:

Currently verifying the change and thinking about a solution that is not being confused with entities that do not need the version_id.

Keep you posted here :wave:

Isengo1989 commented 2 months ago

Closed - PR was opened -> https://github.com/shopware/docs/pull/1473