How to delete a unique key in multiple columns?

How do I change a unique key added to multiple columns in Laravel? Basically, what should go in the down () function of this migration code:

public function up()
{
    Schema::table('topics', function($table)
    {
        $table->unique(array('subject_id', 'grade_id', 'semester_id', 'name'));
    }
}


/**
 * Reverse the migrations.
 *
 * @return void
 */

public function down()
{
    Schema::table('topics', function($table)
    {

    }
}
+4
source share
2 answers

To remove a unique index , you use dropUnique('name_of_index').

If you do not specify an index name in the second parameter unique(), the index name will be tableName_fieldsSeperatedByUnderscore_unique.

public function down()
{
    Schema::table('topics', function($table)
    {
        $table->dropUnique('topics_subject_id_grade_id_semester_id_name_unique');
    }
}
+13
source

There are two approaches to removing a unique index:

: dropUnique() , , "tableName_fieldsSeperatedByUnderscore_unique".

Schema::table('users', function (Blueprint $table) {
      $table->dropUnique(['email']);
});

"email".

: , Marwelln, . dropUnique(), . , . :

Schema::table('users', function (Blueprint $table) {
          $table->dropUnique('users_email_unique');
});
+1

Source: https://habr.com/ru/post/1542269/


All Articles