Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add unique constraint to column with LongText datatype in laravel 5.7

Tags:

laravel-5

Can i add unique constraint to LongText column in laravel. I mean, for example i have table having body column with LongText datatype, then how i can make it unique.

  $table->LongText('body')->unique();

When i do this it will generate the following SQL error.

   Illuminate\Database\QueryException  : SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'long_questi
on' used in key specification without a key length (SQL: alter table `long_questions` add unique `long_questions_long_question
_unique`(`long_question`))

I need need a solution for this to make a LongText column unique... please give me any suggestion.

like image 799
Riaz Khan Avatar asked Mar 04 '23 11:03

Riaz Khan


1 Answers

According to me. You can't make text to unique.

string can be .

$table->string('sensitive_string', 255)->unique();

like image 139
Jaykant Avatar answered Mar 06 '23 23:03

Jaykant