我想将迁移脚本中的一个字段添加到表中并检查唯一性。我尝试以两种方式做到这一点,我在下面给出。但是它们都没有为 PostgreSQL 中的字段创建正确的索引。字段本身已创建,但索引未创建。可能是什么问题呢?
选项1
public function up()
{
Schema::table('testtable', function (Blueprint $table) {
$table->string( 'testfield' )->unique();
});
}
选项 2
public function up()
{
Schema::table('testtable', function (Blueprint $table) {
$table->string( 'testfield' );
$table->unique( 'testfield', 'testfield_unique' );
});
}
您需要查看的不是索引,而是约束。
一)
2)