0

I have a DB with a column of null values but now I want to change it for nullable(false).

Doing a migration I tried

$table->string('route',50)->nullable(false)->default('000 route')->change();

but it says

SQLSTATE[01000]: Warning: 1265 Data truncated for column 'route' at row 1 (SQL: ALTER TABLE address CHANGE route VARCHAR(50) DEFAULT '000 route' NOT NULL COLLATE utf8mb4_unicode_ci)

Is there any way to do it using Laravel migration?

Thank you in advance.

CarlosZ
  • 1,026
  • 1
  • 9
  • 16

1 Answers1

0

There is also another way to do it, which is by dropping and the column, and recreate a new column, for example, to drop the table:

  $table->dropColumn('route');

and try to recreate the column again:

 $table->string('route', 50)->default('000 route');

I hope this is helpful for you.