I have two migrations as shown below:
2016_02_03_071404_create_company_users_table.php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCompanyUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('company_users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('company_id')->unsigned();
$table->foreign('company_id')->references('id')->on('companies');
$table->char('role', 20);
$table->text('first_name');
$table->text('last_name');
$table->integer('age');
$table->string('email')->unique();
$table->text('password');
$table->text('login_type');
$table->string('phone_number')->unique();
$table->integer('verified')->default(0);
$table->text('profile_picture');
$table->text('facebook_id');
$table->text('twitter_id');
$table->text('linkedIn_id');
$table->text('google_plus_id');
$table->text('current_location');
$table->text('established_year');
$table->text('device_type');
$table->text('device_token');
$table->text('device_model');
$table->text('device_os_version');
$table->text('last_login');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropifExists('company_users');
}
}
2016_01_28_144808_create_jobs_table.php
<?php
use Carbon\Carbon;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->text('job_title');
$table->text('job_description');
$table->text('job_industry');
$table->text('job_location');
$table->integer('job_experience');
$table->text('employment_type');
$table->bigInteger('recruiter_id')->unsigned();
$table->foreign('recruiter_id')->references('id')->on('company_users');
$table->tinyInteger('status')->default(1);
$table->timestamp('posted_date')->default(Carbon::now()->toDateTimeString());
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropifExists('jobs');
}
}
When I run php artisan migrate
I get the following error:
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table jobs
add constraint jobs_recruiter_id_foreign foreign
key (recruiter_id
) references company_users
(id
))
[PDOException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
Please help.