How can I update the data type of a column inside a table in Laravel?

Viewed 59

I am trying to update the data type of my column due to it requiring encryption. I created a new migration to do so and have tried this:

public function up()
{
    Schema::table('users', function(Blueprint $table) {
        $table->dropColumn(['team', 'service_number']);
        $table->string('team', 188);
        $table->string('service_number', 188);
    });
}

However, I get this error:

SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'team' (SQL: alter table `users` add `team` varchar(1024) not null, add `service_number` varchar(1024) not null)

How can I update the data type of my columns in my table?

1 Answers

I think you need to do this (though that won't drop the columns):

    $table->string('team', 188)->change();
    $table->string('service_number', 188)->change();
Related