主表民意調查PHP工匠遷移外鍵錯誤
public function up()
{
Schema::create('poll', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->string('poll_question', 255);
$table->boolean('status',1)->default(0)->index();
$table->unsignedInteger('order');
});
}
詳細信息表
public function up()
{
Schema::create('poll_option', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('poll_id');
$table->string('poll_option', 255);
$table->unsignedInteger('vote_poll_option');
$table->unsignedInteger('order');
$table->boolean('status',1)->default(0)->index();
$table->foreign('poll_id')->references('id')->on('poll')->onUpdate('cascade')->onDelete('cascade');
});
}
當我運行PHP的工匠與外鍵
SQLSTATE[HY000]: General error: 1005 Can't create table
mydb
.#sql-6f4_433
(errno: 150 "Foreign key constraint is incorrectly formed")
注:我使用laravel 5.2和MySQL類型已經InnoDB的什麼是主要原因不正確地形成
可能$表 - >整數( 'poll_id') - >無符號(); –
或$ table-> unsignedInteger('poll_id') – ClearBoth