Laravel primary key

3

How can I change the primary key in laravel by default?

<?php

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

class AddSubcategorias extends Migration
{

public function up()
{
    Schema::create('categorias', function (Blueprint $table) {
        $table->primary(array('acronimo_categorias', 3));
        $table->string('descripcion', 50);
        $table->string('registro_calidad' ,1);
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::dropIfExists('categorias');
}
}

In laravel's documentation he says that putting primary should also work and tested this way:

$table->primary('acronimo_categorias,', 3);

But it does not work either, use laravel 5.2

    
asked by Alberto Cepero de Andrés 01.06.2017 в 01:23
source

1 answer

2

The correct form according to Laravel's syntax would be something like that, first define the field and then mark it as a primary index:

public function up()
{
    Schema::create('categorias', function (Blueprint $table) {
        $table->char('acronimo_categorias', 3);
        $table->string('descripcion', 50);
        $table->string('registro_calidad' ,1);

        $table->primary('acronimo_categorias');
    });
}
    
answered by 01.06.2017 / 02:03
source