)我将表迁移到数据库时遇到问题。它是原始的wersion表(工作):
public function up()
{
Schema::create('revisions', function ($table) {
$table->increments('id');
$table->string('revisionable_type');
$table->integer('revisionable_id');
$table->integer('user_id')->nullable();
$table->string('key');
$table->text('old_value')->nullable();
$table->text('new_value')->nullable();
$table->timestamps();
$table->index(array('revisionable_id', 'revisionable_type'));
});
}
我重做此表:
public function up()
{
Schema::create('revisions', function (Blueprint $table) {
$table->increments('id');
$table->string('revisionable_type');
$table->integer('revisionable_id');
$table->integer('user_id')->unsigned();
$table->string('key');
$table->text('old_value')->nullable();
$table->text('new_value')->nullable();
$table->timestamps();
});
Schema::table('revisions', function(Blueprint $table) {
$table->foreign('user_id')->references('id')->on('users');
});
}
我无法添加此表因为工匠返回错误:
[Illuminate \ Database \ QueryException] SQLSTATE [HY000]:常规 错误:1005无法创建表
kurwa_magazyn
。#s ql-1a68_a98
(错误:150“外键约束形成错误”)(S QL: alter tablerevisions
添加约束revisions_user_id_foreign
fore ign key(user_id
)引用users
(id
))[PDOException] SQLSTATE [HY000]:常规错误:1005无法创建 表
kurwa_magazyn
。#s ql-1a68_a98
(错误:150“外键 约束不正确形成“)