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

Asked

Viewed 1,780 times

1

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

In this case as the structure of the method up() in a Migrations modifying a column attribute?

1 answer

1


To make a change in the field, first add depence doctrine/dbal in 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 have made a mistake, create a new Migration and place the column to change and specify the changes with the ->change() at the end, then perform the migrate and the magic happens.

source: https://laravel.com/docs/5.3/migrations#modifying-Columns

Browser other questions tagged

You are not signed in. Login or sign up in order to post.