मैं एक laravel डेटाबेस प्रवास लिखने की कोशिश कर रहा हूँ, लेकिन मैं एक विदेशी कुंजी के बारे में निम्न त्रुटि हो रही है:Laravel प्रवास को नहीं जोड़ सकते विदेशी कुंजी
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'category_id' doesn't exist in table (SQL: alter table `subcategories` add constraint subcategories_category_id_foreign foreign key (`category_id`) references `categories` (`id`))
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'category_id' doesn't exist in table
categories
और subcategories
टेबल बनाया मिलता है लेकिन विदेशी कुंजी नहीं है। यहां मेरा माइग्रेशन है:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCategoryTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('categories', function ($table) {
$table->increments('id')->unsigned();
$table->string('name')->unique();
});
Schema::create('subcategories', function ($table) {
$table->increments('id')->unsigned();
$table->foreign('category_id')->references('id')->on('categories');
$table->string('name')->unique();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('categories');
Schema::drop('subcategories');
}
}
कोई विचार? धन्यवाद!
आपको ऑटो वृद्धिशील फ़ील्ड की आवश्यकता नहीं है क्योंकि केवल विदेशी कुंजी संदर्भ को हस्ताक्षरित किया गया है। –