Laravel 5 Tutorial for beginners : how to user make:migration and make:rollback in laravel Database Migration & Schema in Laravel 5.3?
Laravel 5 Tutorials - How to Generating database migrations in laravel 5.3? make:migration command in Laravel 5.3 will help us to create database tables using Artisan CLI. All migration file as we have created before will saved in database\migrations folder.
Please read :
Migration mean a facility in laravel used to change or make any tables or columns in the database. The schema Builder is used to create a database schema. With migrations and schema builder will be easier when we make great project and with a different developer to be the developer of this does not need to import/export the database but just use migration.
To use the migration, you must have connected to your database before.
You can create migration using more options like using The --table and --create Options to artisan command :
All migration file as we have created before will saved in database\migrations folder.
After success create migration file, at default migration file in database\migrations folder, look this migrations schema file.
Migration Structure
Just configuration and then execute this artisan command to create our table :
See you next Lessons..............
Please read :
Migration mean a facility in laravel used to change or make any tables or columns in the database. The schema Builder is used to create a database schema. With migrations and schema builder will be easier when we make great project and with a different developer to be the developer of this does not need to import/export the database but just use migration.
To use the migration, you must have connected to your database before.
Generating Migrations
Follow this artisan command to make new migration :
php artisan make:migration create_users_table
You can create migration using more options like using The --table and --create Options to artisan command :
php artisan make:migration create_users_table --create=users
php artisan make:migration add_votes_to_users_table --table=users
All migration file as we have created before will saved in database\migrations folder.
After success create migration file, at default migration file in database\migrations folder, look this migrations schema file.
Migration Structure
<?php
use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
class CreateBiodataTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('biodata', function (Blueprint $table) {
$table->increments('id');
$table->string('titles');
$table->string('descriptions');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('biodata');
}
}
Running Migrations
You can create all your tables in the function up(), you know, function up() will create any table or column to our database, and the function down() is to drop or delete any table and column from our database.Just configuration and then execute this artisan command to create our table :
php artisan migrate
Rolling Back Migrations
migrate:rollback command use to drop our table, see example below
php artisan migrate:rollback
Video Tutorial Database Migration & Schema in Laravel 5.3
See you next Lessons..............
COMMENTS