Laravel migration (errno: 150 “Foreign key constraint is incorrectly formed”)

后端 未结 18 2462
谎友^
谎友^ 2020-12-05 14:15

I have an orders table and a have a sell_shipping_labels which references orders.id as a foreign. However when I run the Laravel migration I get th

18条回答
  •  醉梦人生
    2020-12-05 15:02

    I was also getting the same error. What i was doing in users table is,

    $table->unsignedInteger('role_id')->default(2); table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');

    But i have created the role table after creating users table. So, i edited the role migration file name date before the users table filename date. Like this,

    2013_01_22_091213_create_roles_table.php
    2014_10_12_000000_create_users_table.php

    And finally it works. Maybe sometime you may get this problem. So, i posted it.

提交回复
热议问题