如何更改 Laravel 中的默认主键?
<?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');
}
}
在 laravel 文档中,它说放置 primary 也应该起作用,我以这种方式对其进行了测试:
$table->primary('acronimo_categorias,', 3);
但它也不起作用,我使用 laravel 5.2
根据 Laravel 语法,正确的方法是这样的,首先定义字段,然后将其标记为主索引: