Ad
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.
php artisan *
migrate:fresh Drop all tables and re-run all migrations
migrate:install Create the migration repository
migrate:refresh Reset and re-run all migrations
migrate:reset Rollback all database migrations
migrate:rollback Rollback the last database migration
migrate:status Show the status of each migration
Ad
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
Schema::table('YourTableName', function (Blueprint $table) { $table->renameColumn('name', 'username'); });
And Run the migration you have done it without losing your data.
php artisan migrate
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad