
How to add columns in existing table using migration in laravel
How to add columns in existing table using migration in laravel
Through many examples, we will learn how to resolve the "How to add columns in existing table using migration in laravel".
-
Add new columns in existing table using migration in laravel 8
//1. Run php artisan make:migration command to create migration file. php artisan make:migration add_publish_to_comments --table=comments //2. Add columns to your migration file under - database\Migrations\<your_migration_filename>.php. public function up() { Schema::table('comments', function (Blueprint $table) { $table->boolean('is_publish')->default(0); }); } public function down() { Schema::table('comments', function (Blueprint $table) { $table->dropColumn('is_publish'); }); } //3. Migration command to create database table structure.</p> //Migrate to this file php artisan migrate --path=database\Migrations\2021_04_12_085751_add_publish_to_comments.php Or //Migrate all files php artisan migrate
You can add columns in existing table using the migration command
php artisan make:migration add_publish_to_comments --table=comments
. Use a specific migration file name which is not already exist in your migrations folder. After that add columns to the migration file and run migrate command. This is how you can add columns to your existing database table in laravel without changing the table structure manually using PhpMyAdmin MySQL Database. Change table name, migration file name as per your requirements.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Create record with unique slug in laravel
- How to display a specific word from a string in laravel
- How to check find method executed successfully in laravel
- How to include header file in laravel
- Use of undefined constant laravel
- Non-static method App\Http\Helper::myFunction() should not be called statically
- Create project table with model and migration
- How to insert multiple rows in mysql using loop in laravel?
- Use withCount() to get total number of records with relationship
- How to get file extension from input type file in laravel
- How to get specific columns using with method in laravel Eloquent relationship
- Touch parent updated_at in Laravel
- How to add a key value pair to existing array in laravel
- Redirect from www to non www in laravel using htaccess
- SQLSTATE[42000]: Syntax error or access violation: 1055
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- How to insert dynamic value to additional column in pivot table in laravel
- How to Access Array in blade laravel
- How to customize pagination view in laravel
- The use statement with non-compound name 'DB' has no effect
- SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table
- How to update record after save method in Laravel
- Laravel append URI in route
- How to call model in blade laravel
- Call to a member function getRelationExistenceQuery() on array in Laravel