如何在Laravel中创建组合键?

Zee:

我尝试了很多方法,但是没有任何效果。我需要向表daily_deals_products添加一个组合键。是在laravel和mysql中开发的。

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateDailyDealsProductsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('daily__deals__products', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('product_id');
            $table->timestamps();

      
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('daily__deals__products');
    }
}
Naveed Ali:
Schema::create("daily__deals__products", function($table) {
    $table->increments('id');
    $table->integer('product_id');
    $table->string('name');
});

DB::unprepared('ALTER TABLE `daily__deals__products` DROP PRIMARY KEY, ADD PRIMARY KEY (  `id` ,  `product_id` )');

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章