How can I change the attribute of a column with Laravel Migrations

1

In my database I created using laravel migrations I have a column called celphone that unfortunately I did not add the ->nullable() attribute when I created it, now that the base is already in production I want to version this change in the table and add the column as nullable so this information is not required.

In this case what is the structure of the up() method in a migrations that modifies a column attribute?

    
asked by anonymous 14.07.2018 / 02:04

1 answer

1

To make a change in the field, first add the doctrine/dbal depot to your composer.json and then you can make the change this way:

Schema::table('users', function (Blueprint $table) {
        $table->string('sexo')->nullable()->change();
});

Translating, if you made a mistake, create a new migration and place the column that you want to change and specify the changes with the ->change() at the end, then run the migrate and the magic happens.

source: link

    
14.07.2018 / 04:42