【发布时间】:2019-12-12 05:37:13
【问题描述】:
我在我的 laravel 应用程序上迁移表时遇到了一些问题。 它总是说
PDOException::("SQLSTATE[HY000]: 一般错误: 1005 无法创建表
gamehosting.replies(errno: 150 "外键约束格式不正确")")
但是我没有看到外键有问题,这里是迁移
public function up()
{
Schema::create('replies', function (Blueprint $table) {
$table->increments('id');
$table->text('body');
$table->integer('question_id')->unsigned();
$table->integer('user_id');
$table->foreign('question_id')->references('id')->on('questions')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('replies');
}
顺便说一句,首先添加此表,然后应添加问题表,但错误会停止迁移。我将它设置为第一个迁移,但仍然存在同样的问题。
【问题讨论】: