رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
ارتباط یک جدول با دو جدول دیگه
#1
سلام. من یه جدولی دارم به اسم change_money و این جدول الان با جدول یوزر در ارتباطه و میخوام به یه جدول دیگه هم در ارتباط باشه. برای یوزر user_id نوشتم و برای جدول دیگه که اسمش currency_type هستش currencu_id در نظر گرفتم ولی فارین کی دوم رو خطا میده نمیتونم ارتباط برقرار کنم
خطایی که میگیرم اینه:
کد:
[Illuminate\Database\QueryException]
 SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL
 : alter table `change_money` add constraint change_money_currency_id_foreig
 n foreign key (`currency_id`) references `currency_type` (`id`))

چیزی که من نوشتم اینه:

        Schema::create('change_money',function(Blueprint $table){
            $table->increments('id');
           $table->tinyInteger('currency_type');
           $table->string('current_money');
           $table->integer('user_id')->unsigned();
           $table->foreign('user_id')->references('id')->on('users');
           $table->integer('currency_id')->unsigned();
           $table->foreign('currency_id')->references('id')->on('currency_type');
           $table->timestamps();
       });

تو فارین کی دوم یعنی :

            $table->integer('currency_id')->unsigned();

           $table->foreign('currency_id')->references('id')->on('currency_type');
پاسخ
تشکر شده توسط:




کاربران در حال بازدید این موضوع: 1 مهمان