由于某种原因,拉勒维尔被搞混了,多元化的人/人,一些理由,它假设我的桌子是人。
我知道如何在不手动指定$table->foreignId('person_id')->constrained('persons')中的表名的情况下绕过这个问题,但是我想知道为什么会发生这种情况?以及要避免/小心的表名。
无法创建表
person_logs(errno: 150“外键约束格式不正确”) (SQL: alterperson_logs添加约束person_logs_person_id_foreign外键(person_id) referencespeople(id))
Schema::create('persons', function (Blueprint $table) {
$table->id('id');
$table->string('firstname');
$table->string('lastname');
});
Schema::create('person_logs', function (Blueprint $table) {
$table->id('id');
$table->string('example');
$table->foreignId('person_id')->constrained();
});发布于 2021-03-17 08:29:53
作为Str::plural()的一部分,它在person上称为person_id,它的复数版本是people。因此,根据Laravel对persons表的约定,正确的命名实际上是people。
因此,将表更改为people或constrained(),第一个参数是表名。
$table->foreignId('person_id')->constrained('persons');https://stackoverflow.com/questions/66669359
复制相似问题