如果使用Postgres 14/MySQL8服务器,我可以定义基于json字段的唯一索引吗?
在下一次迁移中:
Schema::create('quiz_categories', function (Blueprint $table) {
$table->id();
$table->json('name')->comment('This column is used for i18n support');
$table->boolean('active')->default(false);
$table->timestamps();
$table->unique(['name', 'active'], 'quiz_categories_name_active_index');
});
我收到错误:
Illuminate\Database\QueryException
SQLSTATE[42704]: Undefined object: 7 ERROR: data type json has no default operator class for access method "btree"
HINT: You must specify an operator class for the index or define a default operator class for the data type. (Connection: pgsql, SQL: alter table "quiz_categories" add constraint "quiz_categories_name_active_index" unique ("name", "active"))
?