v2.5.2
Giriş yap

laravel migration error

kenanaga
789 defa görüntülendi
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateKategoriUrunTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('kategori_urun', function (Blueprint $table) {

            $table->increments('id');
            $table->integer('kategori_id')->unsigned();
            $table->integer('urun_id')->unsigned();

            $table->foreign('kategori_id')->references('id')->on('kategori')->onDelete('cascade');
            $table->foreign('urun_id')->references('id')->on('urun')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('kategori_urun');
    }
}

kenanaga
1840 gün önce

Migrating: 2019_11_12_202256_create_kategori_urun_table

Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table kategori_urun add constraint kategori_urun_kategori_id_foreign foreign key (kategori_id) references kategori (id) on delete cascade)

at /home/kenan/ticaret/vendor/laravel/framework/src/Illuminate/Database/Connection.php:665

661|         // If an exception occurs when attempting to run a query, we'll format the error
662|         // message to include the bindings with SQL, which will make this exception a
663|         // lot more helpful to the developer instead of just the database's errors.
664|         catch (Exception $e) {

> 665| throw new QueryException(

666|                 $query, $this->prepareBindings($bindings), $e
667|             );
668|         }
669| 

Exception trace:

1 PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint")

  /home/kenan/ticaret/vendor/laravel/framework/src/Illuminate/Database/Connection.php:459

2 PDOStatement::execute()

  /home/kenan/ticaret/vendor/laravel/framework/src/Illuminate/Database/Connection.php:459

Please use the argument -v to see more details.