۱ امیرحسین راستی
_A migration Error_
جامعه پی اچ پی ایجاد شده در ۳۰ مهر ۱۴۰۱

همین اول بسم الله به ارور خوردم ?

سلام هنگام migrate کردن جدول products به ارور می‌خورم:: بقیه ی جدول‌ها migrate میشن و مشکلی نیست ولی این یکی هرکاری میکنم ارور میده که foreign key مشکل داره.538d-Screenshot 2022-10-22 211339.png

<?php
use Illuminate\\Database\\Migrations\\Migration;
use Illuminate\\Database\\Schema\\Blueprint;
use Illuminate\\Support\\Facades\\Schema;
return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->char('title');
            $table->text('description');
            $table->char('thumbnail_url');
            $table->char('demo_url');
            $table->char('source_url');
            $table->unsignedInteger('price');
            $table->unsignedInteger('category_id');
            $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
            $table->unsignedBigInteger('owner_id');
            $table->foreign('owner_id')->references('id')->on('users')->onDelete('cascade');
            $table->timestamps();
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products');
    }
};

سلام،

از unsignedBigInteger استفاده کنید.

$table->unsignedBigInteger('category_id');
محسن موحد ۰۱ آبان ۱۴۰۱، ۱۸:۰۶