Mysql 无法在迁移Laravel时创建多个主键
我正在为我工作的企业的数据库进行迁移 问题是同一个表有4个主键,但这个错误是由Laravel抛出的 我的迁移是这样的:Mysql 无法在迁移Laravel时创建多个主键,mysql,laravel,Mysql,Laravel,我正在为我工作的企业的数据库进行迁移 问题是同一个表有4个主键,但这个错误是由Laravel抛出的 我的迁移是这样的: Schema::create('ventas', function (Blueprint $table) { $table->bigIncrements('id'); $table->integer('empresa_id')->primary(); $table->integer('moneda_id')
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');
我怎样才能解决这个问题
谢谢 试试这个
public function up()
{
Schema::create('ventas', function (Blueprint $table) {
$table->id();
$table->foreignId('empresa_id')->nullable()->constrained()->onDelete('restrict');
$table->foreignId('moneda_id')->nullable()->constrained()->onDelete('restrict');
$table->foreignId('user_id')->nullable()->constrained()->onDelete('restrict');
$table->timestamps();
});
}
每个表只能有一个主键,但是有复合主键keaysHow我可以创建一个复合主键吗?你可以在m上有一个OK,但我个人觉得laralveland雄辩可怕三个独立的键之间有区别可能一个主键+两个唯一的约束和一个带三列的复合键。您需要哪一个?您似乎还有一个自动递增的id字段。如果你有这样一个字段,那么你应该把它作为主键,否则我就不明白它为什么在那里。它告诉我异化方法不存在:它适用于laravel 7