Php Laravel外键格式不正确
我在迁移laravel应用程序上的表时遇到一些问题。 它总是说 PDOException::(“SQLSTATE[HY000]:一般错误:1005无法创建表Php Laravel外键格式不正确,php,laravel,Php,Laravel,我在迁移laravel应用程序上的表时遇到一些问题。 它总是说 PDOException::(“SQLSTATE[HY000]:一般错误:1005无法创建表游戏主机回复(错误号:150“外键约束格式不正确”)) 但是我认为外键没有问题,这里是迁移 public function up() { Schema::create('replies', function (Blueprint $table) { $table->increments('
游戏主机回复(错误号: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');
}
顺便说一句,它首先添加这个表,然后应该添加问题表,但错误会停止迁移。我将它设置为第一个迁移,但仍然存在相同的问题。这意味着questions
表上的id
不是无符号整数<代码>问题id
在数据库中的类型必须与问题
表中的id
相同。它可能失败的另一个原因是问题
表和答复
表没有相同的排序规则或引擎