Skip to content
Advertisement

Laravel: Rename table field without deleting data during migration

I’m trying to change “name” into “username” without deleting the existing records.

I tried all of these but it just wipes out the data in the table.

JavaScript

Advertisement

Answer

For that you have to follow below steps!

1. install Doctrine/dbal

composer require doctrine/dbal

2. create a migration file to rename column name

php artisan make:migration updateTableColumnName

3. add below code to edit your column name

JavaScript

And Run the migration you have done it without losing your data.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement