Skip to content

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

Closed
@flytomek

Description

@flytomek

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,
  1. 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 
  1. Add additional field in the entity definition class:
new ReferenceVersionField(ProductDefinition::class, "product_version_id"),

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions