Yii2 Migrations: How to unique constraint on two columns?

I’d like to add a unique constraint to an existing table. The unique constraint spans two existing columns (event, player). How do I do that?

1 Like

Oh, it’s really easy. Just make an index and set the Unique Flag to 1:


 $this->createIndex(

            'idx-unique-teilnehmer-durchfuehrung-spieler',

            'teilnehmer',

            'durchfuehrung, spieler',

            1

        );

1 Like
$this->createIndex(
            '{{%idx-unique-user-firstname-lastname}}',
            '{{%user}}',
            ['firstname', 'lastname'],
            true
        );