Laravel Migrations

Laravel Migrations

Are like version control for your database, allowing your team to easily modify and share the application's database schema.

Generating Migrations

Php artisan make:migration create_users_table
Php artisan make:migration create_users_table --create=users

php artisan make:migration add_votes_to_users_table --table=users

Running Migrations

Php artisan migrate

Migration Structure

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateFlightsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('flights', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('airline');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('flights');
    }
}

Tables

Columns

Indexes

Laravel Migrations — Structure map

Clickable & Draggable!

Laravel Migrations — Related pages: