1

If with postgres 14 /mysql 8 servers can I define unique index based on json field ?

With next migration :

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');
});

I got error :

  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"))

?

4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.