علت ارور هنگام migrateکردن جداول!

پرسیده شده
فعالیت 1009 روز پیش
دیده شده 377 بار
0

سلام استاد، وقتتون بخیر

ببخشید یه سوال داشتم من کدهامو مشابه شما توی ویدیو زدم ولی وقتی migrate کردم به ارور زیر برخوردم:

  SQLSTATE[HY000]: General error: 1005 Can't create table `shopDB`.`order_product` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `order_product` add constraint `order_product_order_id_foreign` foreign key (`order_id`) references `orders` (`id`) on delete cascade)

علاوه بر اینکه دوتا فیلد phone و address هم به جدول users اضافه نشدن، مشکل از چی هستش؟ 

کدهای مربوط به ادکردن فیلدها به جدول user + کد جدول order_prodcut رو هم براتون گذاشتم، ممنون میشم بررسی کنید بگید بهم کجا احیاناً اشتباهی رخ داده!

class AddPhoneNumberAndAddressIntoUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->char('phone_number')->nullable();
            $table->string('address')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            //
        });
    }
}

 

public function up()
    {
        Schema::create('order_product', function (Blueprint $table) {
            $table->bigInteger('order_id');
            $table->bigInteger('product_id');
            
            $table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');
            $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
            
            $table->timestamps();
        });
    }
فایل پیوست

امیر ابوئی
امیر ابوئی

1 تیر 00

2
حذف شده

سلام 

 

احتمالا type فیلد id در جدول product و جدول order با این جدول شما یکی نیست. 

 

شما اینجا bigInteger تعریف کردید .. داخل جداول product و order هم فیلد id به همین صورت تعریف شده؟

فایل پیوست

مهرداد سامی

توسط

مهرداد سامی

1 تیر 00

حذف شده
بله همه شون همین هستش!
امیر ابوئی

1 تیر 00

0
حذف شده

متاسفانه حواسم نبود و در migration جدول users، مقدار id به صورت id ست شده بود ن bigIncrements که درستش کردم و حل شد

ممنون

فایل پیوست

امیر ابوئی

توسط

امیر ابوئی

2 تیر 00