Hello Devs,
In this tutorial, we will learn How To Create Table Migration In Laravel 8
We will also show how to run migration and rollback migration and how to create migration using command in laravel 8.
Follow this step-by-step guide below.
Create Migration:
php artisan make:migration create_posts_table
database/migrations/2020_04_01_064006_create_posts_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePostTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->text('dec');
$table->longText('party_name')->nullable();
$table->integer('votes');
$table->tinyInteger('votes')->default(0);
$table->boolean('confirmed');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('posts');
}
}
Run Migration:
php artisan migrate
Create Migration with Table:
php artisan make:migration create_posts_table --table=posts
Migration Rollback:
php artisan migrate:rollback
May this example help you.