【发布时间】:2016-05-13 15:44:32
【问题描述】:
我有两个迁移,如下所示:
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');
}
}
当我运行php artisan migrate 时出现以下错误:
[照亮\数据库\查询异常]
SQLSTATE[HY000]: 一般错误: 1215 无法添加外键约束 (SQL: alter table jobs add constraint jobs_recruiter_id_foreign foreign
关键 (recruiter_id) 引用 company_users (id))
[PDO异常]
SQLSTATE[HY000]: 一般错误:1215 无法添加外键约束
请帮忙。
【问题讨论】:
标签: sql migration laravel-5.2