I am trying to create a primary key-foreign key relation using in laravel, but I keep getting this error
SQLSTATE[HY000]: General error: 1005 Can't create table `volga_2`.`employees` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `employees` add constraint `employees_dept_id_foreign` foreign key (`dept_id`) references `departments` (`id`))
I cant seem to find out where am I going wrong, since I have made changes into the schema, after looking at other answers on SO.
When I run php artisan migrate the error above pops up, and its a partial migration.
Any pointers into this would be awesome, since I have been looking for a while for a solution to this!
Thanks!
Employee Table
Schema::create('employees', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('dept_id')->unsigned();
$table->foreign('dept_id')->references('id')->on('departments');
$table->integer('salary_id')->unsigned();
$table->foreign('salary_id')->references('id')->on('salary');
$table->string('name');
$table->string('gender');
$table->timestamp('date_of_joining');
$table->dateTime('date_of_birth');
$table->timestamps();
Departments Table
Schema::create('departments', function (Blueprint $table) {
$table->increments('id');
$table->string('dept_name');
$table->timestamps();
Salaries Table
Schema::create('salaries', function (Blueprint $table) {
$table->increments('id');
$table->string('monthlySalary');
$table->timestamps();
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire