Laravel migration foreign key issue

后端 未结 2 734
悲&欢浪女
悲&欢浪女 2020-12-21 12:31

I have created categories table using categories migration and then i am trying to create products table using another migration with foreign key categories_id in products t

2条回答
  •  醉梦人生
    2020-12-21 12:53

    unsigned() should be defined while setting the type, not while setting the foreign key. Also, reference() should be references()

    The corresponding lines should be changed like this:

    $table->integer('category_id')->unsigned();
    $table->foreign('category_id')->references('id')->on('categories');
    

提交回复
热议问题