laravel errno 150 foreign key constraint is incorrectly formed

前端 未结 11 1571
陌清茗
陌清茗 2020-12-14 03:09

Can anybody help me to solve this problem?

There are 3 tables with 2 foreign keys:

Schema::create(\'users\', function (Blueprint $table) {
    $table-&         


        
11条回答
  •  难免孤独
    2020-12-14 03:54

    If the reference table primary key is in BigIcrements then Use the BigInteger for foreign key also like below

    Table ATable

    public function up()
    {
        Schema::create('a_tables', function (Blueprint $table) {
            $table->bigIncrements('id');
       }
    }
    

    TABLE BTable

    public function up()
    {
        Schema::create('b_tales', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->bigInteger('a_tables_id')->unsigned();
         $table->foreign('a_tables_id')->references('id')->on('a_tables')->onDelete('cascade');
       }
    }
    

提交回复
热议问题