I'm new to Laravel, and I'm having issues with Migrations.
The table name spellings are accurate but I still get the error.
The error states
SQLSTATE[HY000]: General error: 1005 Can't create table
first_db
.#sql-41c_2f
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter tablefees
add constraintfees_academic_id_foreign
foreign key (academic_id
) referencesacademics
(academic_id
))
The error points to this file below:
Schema::create('fees', function (Blueprint $table) {
$table->increments('fee_id');
$table->integer('academic_id')->unsigned;
$table->integer('level_id')->unsigned;
$table->integer('fee_type_id')->unsigned;
$table->string('fee_heading',200)->nullable;
$table->float('amount', 8, 2);
$table->foreign('academic_id')->references('academic_id')->on('academics');
$table->foreign('level_id')->references('level_id')->on('levels');
$table->foreign('fee_type_id')->references('fee_type_id')->on('feestype');
});
Is there something I'm doing wrong?
academic_id
throws this. It could be that theacademics
table doesn't exist, doesn't have that field, has that field but with a different definition (char, signed int, something like that) or something like that? – Nanne$table->integer('academic_id')->unsigned()
use unsigned like this – Gihan Lakshan