Composite FOREIGN (yes I said foreign) key


I have a table called invoice_item. This table has a composite foreign key of "entity_id" and "table_name". It is a polymorphic relationship table. In MySQL, and most other relational databases, you can create a foreign key (or list of indexes) to reference a composite primary key like so…

FOREIGN KEY (`entity_id`,`table_name`) 

    REFERENCES invoice_item(`entity_id`,`table_name`)

How can this be achieved using the standard Yii2 migration script "createTabel" method?


I know this is added to the 2.1.x milestone (

I can’t help you for now…