Answer the question
In order to leave comments, you need to log in
Problem with migration, how to create primery and unique keys with their own names?
I am just starting to learn laravel, I wrote the following lines in migration:
public function up()
{
$tableName = 'nx_path';
Schema::create($tableName, function (Blueprint $table) {
$table->smallInteger('id',true, true)->primary();
$table->smallInteger('node',false, true)->unique();
$table->string('title', 255)->default('');
$table->string('keywords', 255)->default('');
$table->string('description', 255)->default('');
$table->string('path', 255)->default('');
$table->text('anchor_pattern');
$table->text('title_synonyms');
});
DB::statement("ALTER TABLE `$tableName` comment 'Ноды и их типы'");
}
Answer the question
In order to leave comments, you need to log in
Use the bigIncrements() function to create an id
instead of a
small integer (usually not used for id) this will not give much savings UPD . I figured out the problem - why it turned out to double add the primary key:
Under the hood $table->smallInteger('id', true, true) will create id as the primary key due to the autoIncrements = true flag (second argument), so calling primary() created the key again. You can simply do:$table->smallInteger('id', true, true);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question