Merhaba arkadaşlar,
Bu hatanın çözümünü çok araştırdım ama bulamadım.
php artisan migrate:fresh dediğimde bu hatayı alıyorum :
SQLSTATE[HY000]: General error: 1825 Failed to add the foreign key constraint on table 'cart_products'. Incorrect options in FOREIGN KEY constraint 'laravel/cart_products_product_id_foreign' (SQL: alter table cart_products add constraint cart_products_product_
id_foreign foreign key (product_id) references products (id) on delete cascade)
Migration dosyası bu şekilde :
Schema::create('cart_products', function (Blueprint $table) {
$table->id();
$table->integer('cart_id')->unsigned();
$table->integer('product_id')->unsigned();
$table->integer('piece');
$table->decimal('price',5,2);
$table->string('status',30);
$table->softDeletes();
$table->timestamps();
$table->foreign('cart_id')->references('id')->on('carts')->onDelete('cascade');
$table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
\Illuminate\Support\Facades\DB::statement('SET FOREIGN_KEY_CHECKS=1;');
});
migrate:fresh
Dediğimde tüm veriler siliniyor. Tablolar arasında eşleyecek veri bulamadığı için mi bu hatayı veriyor acaba ?