How to fix foreign key error when running migration

前端 未结 2 1786
醉话见心
醉话见心 2021-01-26 12:34

I don\'t know why it\'s still don\'t work and show this:

Illuminate\\Database\\QueryException : SQLSTATE[HY000]: General error: 1005 Can\'t create tabl

相关标签:
2条回答
  • 2021-01-26 13:27

    You foreign key needs to have the same type as the key it references. Therefor the second table foreign key doba needs to be change to this, becuase you use BigIncrements() in the first table primary key.

    $table->unsignedBigInteger('doba');
    
    0 讨论(0)
  • 2021-01-26 13:35

    The problem here is that id_druhu in druh_knihies is defined as bigIncrements and you create doba as unsignedInteger and when using foreign key type should be exactly same. So in this case instead of

    $table->unsignedInteger('doba');
    

    you should use

    $table->unsignedBigInteger('doba');
    
    0 讨论(0)
提交回复
热议问题