【发布时间】:2016-11-25 00:10:51
【问题描述】:
主表 POll
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 artisan 时
SQLSTATE[HY000]: 一般错误: 1005 无法创建表
mydb.#sql-6f4_433(errno: 150 "外键约束格式不正确")
注意:我正在使用 laravel 5.2 和 mysql 类型已经 Innodb 不正确形成的主要原因是什么
【问题讨论】:
-
五月 $table->integer('poll_id')->unsigned();
-
或$table->unsignedInteger('poll_id')
标签: php mysql laravel foreign-keys artisan-migrate