Laravel:在迁移中未应用unique()。

huangapple go评论59阅读模式
英文:

Laravel : unique() not applied in migration

问题

为什么 unique() 没有生效?
我在 PgAdmin 的约束列表中没有看到它应用在这个列上。

英文:

In my migration, I have this column:

$table->foreignId('child_id')
      ->references('id')
      ->on('myschema.users')
      ->nullable()
      ->unique()
      ->constrained();

Why unique() is not applied?
I don't see it in the list of constaints in PgAdmin for this column.

答案1

得分: 1

因为 'child_id' 是外键,而外键通常是唯一的,所以唯一不会被应用,而且在迁移中创建外键时不需要提到唯一性。希望这对您有帮助。

英文:

Because 'child_id' is foreign_key and always foreign_key is unique that's why unique is not applied also you don't need to mention unique while creating forign_key in migration. I hope this can be helpful to you.

huangapple
  • 本文由 发表于 2023年7月6日 17:51:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76627577.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定