【发布时间】:2020-08-29 15:42:27
【问题描述】:
我正在为我工作的企业的数据库进行迁移。
问题是同一个表有 4 个主键,但这个错误是由 Laravel 抛出的。
这就是我的迁移的样子:
Schema::create('ventas', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('empresa_id')->primary();
$table->integer('moneda_id')->primary();
$table->integer('user_id')->primary();
$table->foreign('empresa_id')->references('id')->on('empresas')->onDelete('restrict');
$table->foreign('moneda_id')->references('id')->on('monedas')->onDelete('restrict');
我该如何解决这个问题?
谢谢!
【问题讨论】:
-
每个表只能有一个主键,但是有复合主键
-
如何创建复合 PK?
-
你可以看看stackoverflow.com/questions/31415213/… m 但我个人觉得 laralveland 雄辩可怕
-
“三个单独的键”(可能是一个主键 + 两个唯一约束)和具有三列的“单个复合键”之间存在差异。你需要哪一个?
-
您似乎也有一个自动增量 id 字段。如果你有这样一个字段,那么你应该把它作为主键,否则我不明白它为什么在那里。