Answer the question
In order to leave comments, you need to log in
How to create indexes for PostgreSQL 10.1 fields in Laravel 5.6 migrations?
I want to add a field in the migration script to the table with a check for uniqueness. I try to do this in two ways, which I give below. But none of them creates the correct index for the field in PostgreSQL. The field itself is created, but the index is not. What could be the problem?
public function up()
{
Schema::table('testtable', function (Blueprint $table) {
$table->string('testfield')->unique();
});
}
public function up()
{
Schema::table('testtable', function (Blueprint $table) {
$table->string('testfield');
$table->unique('testfield', 'testfield_unique');
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question