Migration Generator Laravel 11+

Generate Laravel migration files from a table and column definition.

Generated Migration

What is a Laravel migration?

A migration is version control for your database schema. Each migration is a PHP class that describes how to build or change a part of your database in a up() method, and how to undo that change in a down() method. Running php artisan migrate applies every pending migration in order; php artisan migrate:rollback reverses them. Because the schema lives in code, every developer and every environment ends up with the same tables, columns, indexes, and constraints.

This generator produces the boilerplate for a Schema::create migration so you do not have to type the class scaffolding, the imports, and every column line by hand. You describe the table and its columns, and it writes a complete, correctly formatted migration using an anonymous class — the modern Laravel 11+ style that needs no class name.

Key behaviours

  • Anonymous class — output uses return new class extends Migration, the Laravel 11+ convention.
  • Automatic id — if you add no columns, the generator inserts $table->id(); for you.
  • Column options — each column can be nullable, unique, and carry a default value.
  • Standard columns — toggle timestamps() and softDeletes().
  • Paired down() — a matching Schema::dropIfExists() is generated for rollbacks.

Available column types

The column type dropdown maps directly to a Blueprint method on the generated line. The following types are supported:

Type Typical database column
stringVARCHAR(255)
integerINT, a 32-bit integer
bigIntegerBIGINT, 64-bit integer
textTEXT, unbounded string
booleanBOOLEAN / TINYINT(1)
float / decimalFLOAT / DECIMAL for numeric values
date / dateTime / time / timestampDate and time variants
json / jsonbJSON document columns
binaryBLOB / BINARY
uuidUUID / CHAR(36)
foreignIdUnsigned BIGINT for foreign keys

Example generated migration

A table named posts with a title (string, unique), a body (text, nullable), and timestamps produces:

<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->string('title')->unique();
            $table->text('body')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('posts');
    }
};

The class name suggestion is built from the table name: posts becomes CreatePostsTable. The generator always quotes default values, so a numeric default such as 0 is emitted as default('0').

How to Use

  1. Table Name — Enter the name of your database table (plural form recommended).
  2. Add Columns — Click "Add Column" and configure the column name, type, and options.
  3. Options — Check timestamps() or softDeletes() to add those standard columns.
  4. Generate — Click to generate the full migration class with up() and down() methods.

Frequently Asked Questions

What is a migration?

A migration is like version control for your database. It allows you to define and share your database schema changes with your team. Migrations are typically paired with Laravel's Schema Builder to create or modify database tables.

What does the generated class name look like?

The class name will be generated as CreateUsersTable based on your table name. You can rename the file with a timestamp prefix like 2024_01_01_000000_create_users_table.php.

Which Laravel versions use the generated code?

The output uses an anonymous class migration (return new class extends Migration), which is the default from Laravel 8.x onward and the recommended style in Laravel 11 and later. Older Laravel versions used a named class with an explicit class name.

What happens if I add no columns?

The generator emits a single $table->id(); line so the migration still creates a valid table with an auto-incrementing primary key. Add columns for every field you want beyond that.

How do nullable, unique, and default options work?

Each column has nullable and unique checkboxes that append ->nullable() and ->unique(). The default field appends ->default(...) and is always quoted as a string, so entering 0 produces default('0') rather than a numeric literal.

How do I add a foreign key?

Choose the foreignId type for the column, which creates an unsigned big integer suitable for a foreign key. The generator does not add the foreign key constraint itself; add ->constrained() or ->constrained('table') manually after generating.

What are timestamps() and softDeletes()?

timestamps() adds created_at and updated_at columns managed automatically by Eloquent. softDeletes() adds a nullable deleted_at column so records are soft-deleted instead of removed. Enable either with the checkboxes.

Where do I put the generated file?

Save the file in the database/migrations directory with a timestamp prefix such as 2024_01_01_000000_create_users_table.php. Then run php artisan migrate to apply it, or php artisan migrate:rollback to reverse it.