【发布时间】:2018-01-06 00:41:53
【问题描述】:
当我将主键从增量更改为字符串 (user_id) 时,我的迁移出现了错误。我似乎没有看到我哪里出错了。我的迁移文件没问题,直到我从 (->increments 和另一个 ->integer) 更改为 (->string on both)。问题是当它迁移氏族成员表时,它说外键格式不正确
我之前的代码。好像还可以,在cmd中迁移没什么问题
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('user_id');
$table->string('fname', 50);
$table->string('lname', 50);
$table->integer('age');
$table->string('gender', 10);
$table->string('address', 50);
$table->timestamps();
});
}
public function up()
{
Schema::create('clanmembers', function (Blueprint $table) {
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('user_id')->on('users')->onDelete('cascade');
$table->integer('clan_id')->unsigned();
$table->foreign('clan_id')->references('clan_id')->on('clans')->onDelete('cascade');
$table->string('bandrole', 50);
$table->timestamps();
});
}
我的代码在我将 ->increments 和 ->integer 更改为两者之后 ->string
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->string('user_id');
$table->string('fname', 50);
$table->string('lname', 50);
$table->integer('age');
$table->string('gender', 10);
$table->string('address', 50);
$table->timestamps();
});
}
public function up()
{
Schema::create('clanmembers', function (Blueprint $table) {
$table->string('user_id');
$table->foreign('user_id')->references('user_id')->on('users')->onDelete('cascade');
$table->integer('clan_id')->unsigned();
$table->foreign('clan_id')->references('clan_id')->on('clans')->onDelete('cascade');
$table->string('clanrole', 50);
$table->timestamps();
});
}
【问题讨论】:
标签: mysql laravel laravel-migrations