The correct naming in Laravel should be:
Schema::create('person', function (Blueprint $table) {
$table->increments('id');
});
Schema::create('student', function (Blueprint $table) {
$table->increments('id');
$table->integer('person_id')->unsigned();
$table->foreign('person_id')->references('id')->on('person');
});
to answer your problem: since the second schema query runs in a single call, it's trying to put a constraint on a column that does not exist; to correct it split the query in to two parts:
Schema::create('student', function (Blueprint $table) {
$table->increments('id');
$table->integer('person_id')->unsigned();
});
Schema::table('student', function (Blueprint $table) {
$table->foreign('person_id')->references('id')->on('person');
});
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community