I am new to Laravel. I have created
users
table previously. employment
table has created in migrations. As the next migration I have alter users
table to add job_id
in employment
table to users
table. When I run migrations it gives above error.
Note :I need to give job_id
in employment
table to users
table as job_id
. soumya is my database name
When I run migrations without the foreign key constraint, it works perfectly.
Migations : employment table
public function up()
{
Schema::create('employment', function (Blueprint $table) {
$table->increments('job_id');
$table->string('job_title');
$table->string('job_description')->nullable()->default(NULL);
$table->string('slug')->unique();
$table->timestamps();
});
}
public function down()
{
Schema::drop('employment');
}
Migrations altering users
table
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->integer('job_id')->after('deleted');
$table->foreign('job_id')->references('job_id')->on('employment');
});
}
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropForeign('users_job_id_foreign');
$table->dropColumn('job_id');
});
}