Yii2 migration "Foreign key constraint is incorrectly formed"

Viewed 1564

This is how I have added the foreign key inside of the migration:

$this->addForeignKey(
        'fk-auth_item_ibfk_1',
        'auth_item',
        'rule_name',
        'auth_rule',
        'name',
        'SET NULL',
        'CASCADE'
    );

Exception:

Exception 'yii\db\Exception' with message 'SQLSTATE[HY000]: General error: 1005 Can't create table `yii`.`#sql-1ab_85` (errno: 150 "Foreign key constraint is incorrectly formed")

Error Info:

Error Info:
Array
(
[0] => HY000
[1] => 1005
[2] => Can't create table `yii`.`#sql-1ab_af` (errno: 150 "Foreign key constraint is incorrectly formed")
)

Any help is appreciated. I haven't got a clue why its happening. I have checked that the fields are of same type and size.

0 Answers
Related