VARCHAR max in laravel 5

- 1 answer

Ad

I have searched all over the web for a tutorial on varchar max. I have even tried

$table->string('name', "MAX");

This gives me an error.

How can I set up varchar max for a blog post for a laravel project. Thanks

Ad

Answer

Ad

There is no "max" constant for VARCHAR in MySQL. Instead you need to define the maximum value of the field yourself.

In order to define max length for a text field just provide max length limit as second parameter:

$table->string('name', 64);

It will result in a VARCHAR column being created in your MySQL database. Keep in mind that if max length is very high, a field of different type might be created instead (mediumtext, longtext).

Ad
source: stackoverflow.com
Ad