Syntax error or access violation: 1101 BLOB, TEXT, GEOMETRY or JSON column can’t have a default value

Today we discuss about an error in Laravel migration for json type and text type. Laravel provide migration feature for quickly create DB table through running just simple php artisan migrate command this command is a Laravel CLI command. There are 2 cases for this error.

1.Suppose you set json column in your migration like

$table->json(‘column’);  and got this error “Syntax error or access violation: 1101 BLOB, TEXT, GEOMETRY or JSON”

So first possibility is that your are using old version of MySQL

Soultion for this either update your mysql version or change migration code

$table->json(‘column’); change this into $table->longText(‘column’); or $table->text(‘column’); will fix your error.

2. Second case, Suppose you write this code in your migration file

$table->longText(‘column’)->default(”); this also given same error “Syntax error or access violation: 1101 BLOB, TEXT, GEOMETRY or JSON”

for quick chang it from $table->longText(‘column’)->default(”); or $table->text(‘column’)->default(”); into $table->longText(‘column’)->nullable(); or $table->text(‘column’)->nullable();

I think this is a good post for fix this error.

Thank you and support us

Phpguruji.com

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow by Email
LinkedIn
Share
Instagram