Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update column collation with laravel

I have a case-insensitive collation column in my table.

col_name : hash_id, collation : utf8mb4_unicode_ci

I am getting results for yA2JeGs and YA2JeGs when I search for former only.

So I need to update the collation to ensure case-sensitivity for that column.

I tried changing the collation for that column creating a new migration file:

public function up()
{
    Schema::table('product_match_unmatches', function (Blueprint $table) {
        $table->string('hash_id')->collate('utf8mb4_bin')->change();
    });
}

Also with $table->string('hash_id')->collation('utf8mb4_bin')->change();

Migration runs successfully but the collation remains the same.

How do I do that in laravel?

like image 317
Azima Avatar asked Jun 26 '19 10:06

Azima


People also ask

How do I change the datatype of a column in Laravel migration?

How to change data type of column in laravel 9 migration ? Step 1 : Install doctrine/dbal package. Step 2 : Generate migration file. Step 3 : Open generated migration file and update.

How do I change the table collation?

You can change the collation of any new objects that are created in a user database by using the COLLATE clause of the ALTER DATABASE statement. This statement does not change the collation of the columns in any existing user-defined tables. These can be changed by using the COLLATE clause of ALTER TABLE.


1 Answers

You need to create new migration and make column case sensitive using laravel schema builder with code mentioned below :

$table->string('columName')->collation('utf8_bin')->change();

https://laravel.com/docs/7.x/migrations

like image 152
Volod Avatar answered Sep 28 '22 16:09

Volod