Export to Laravel Migrations

Easily transition from designing your database models in DrawSQL to scaffolding your Laravel codebase without having to recreate those tables and columns.

DrawSQL can generate the necessary Laravel migration files to represent your database schema diagram. In the export, each table will be self-contained within its own migration class, and its file name will automatically match Laravel's convention. Behind the scenes, this functionality is powered by Jason's amazing Laravel Shift Blueprint package.

To get your Laravel migration exports:

  1. From the diagram editor, click on 'File' in the menubar, then "Export"

  2. Select the "Laravel Migrations" option

  3. Click on the "Start export" button

  4. Once the export process is complete, a .zip file containing the migration files will automatically be downloaded. Drop them into your app's database/migrations folder and run php artisan migrate.

Sample export output

2023_07_22_134044_create_employees_table.php

 <?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::disableForeignKeyConstraints();

        Schema::create('employees', function (Blueprint $table) {
            $table->integer('employee_id', 11)->primary()->autoIncrement();
            $table->string('first_name', 20)->nullable()->default(null);
            $table->string('last_name', 25);
            $table->string('email', 100);
            $table->string('phone_number', 20)->nullable()->default(null);
            $table->date('hire_date');
            $table->integer('job_id', 11);
            $table->foreign('job_id')->references('job_id')->on('jobs');
            $table->decimal('salary', 8, 2);
            $table->integer('manager_id', 11)->nullable()->default(null);
            $table->foreign('manager_id')->references('employee_id')->on('employees');
            $table->integer('department_id', 11)->nullable()->default(null);
            $table->foreign('department_id')->references('department_id')->on('departments');
        });

        Schema::enableForeignKeyConstraints();
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('employees');
    }
};

2023_07_22_134044_create_regions_table.php

 <?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('regions', function (Blueprint $table) {
            $table->integer('region_id', 11)->primary()->autoIncrement();
            $table->string('region_name', 25)->nullable()->default(null);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('regions');
    }
};

Prefer a Blueprint draft.yaml?

If you use Laravel Shift Blueprint to scaffold models, controllers, and factories, pick the Laravel Blueprint export instead — it produces a draft.yaml of model definitions you can feed straight to php artisan blueprint:build.

AdonisJS

Working in AdonisJS? The AdonisJs export generates Knex.js migration files instead, with support for Adonis v4 and v5.

Still have a question? We'd love to help!