How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: Laravel Migration Column Types — Cheat Sheet
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > Laravel Migration Column Types — Cheat Sheet
Web Development

Laravel Migration Column Types — Cheat Sheet

how7o
By how7o
Last updated: May 23, 2026
5 Min Read
Laravel migration column types cheat sheet
SHARE

Laravel’s schema builder lets you declare column types with a fluent API. Below is a reference cheat sheet of the most-used methods on the Blueprint object — what they create, when to use them, and the modifiers (nullable, default, unsigned) that apply to most types.

Contents
  • IDs and timestamps
  • Strings and text
  • Numbers
  • Dates and times
  • Booleans, enums, binary
  • Foreign keys (modern form)
  • Column modifiers
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 on Laravel 11. Originally published 2022-09-11, rewritten and updated 2026-05-17.

IDs and timestamps

$table->id();                       // unsigned BIGINT auto-increment primary key, named "id"
$table->bigIncrements('id');        // explicit form of id()
$table->increments('id');           // unsigned INT auto-increment primary key
$table->uuid('id')->primary();      // UUID primary key

$table->timestamps();               // adds created_at + updated_at (TIMESTAMP)
$table->timestampsTz();             // TIMESTAMP WITH TIME ZONE (PostgreSQL-aware)
$table->nullableTimestamps();       // same as timestamps(), but nullable
$table->softDeletes();              // adds deleted_at (nullable TIMESTAMP) for soft deletes
$table->rememberToken();            // adds remember_token VARCHAR(100) NULL
Laravel migration column types — ids, strings, numbers, foreign keys, timestamps, modifiers

Strings and text

$table->string('email');            // VARCHAR(255)
$table->string('name', 100);        // VARCHAR(100)
$table->char('code', 4);            // CHAR(4) — fixed-length

$table->text('body');               // TEXT — up to 64 KB
$table->mediumText('body');         // MEDIUMTEXT — up to 16 MB
$table->longText('body');           // LONGTEXT — up to 4 GB

$table->json('payload');            // JSON column (MySQL 5.7+, MariaDB 10.2+, PostgreSQL)
$table->jsonb('payload');           // JSONB — PostgreSQL only, indexed

Numbers

$table->integer('votes');           // INTEGER
$table->bigInteger('votes');        // BIGINT
$table->smallInteger('votes');      // SMALLINT
$table->tinyInteger('votes');       // TINYINT
$table->mediumInteger('count');     // MEDIUMINT

$table->unsignedBigInteger('uid');  // BIGINT UNSIGNED
$table->unsignedInteger('count');   // INT UNSIGNED

$table->decimal('amount', 10, 2);   // DECIMAL(10,2) — money, exact
$table->float('rate');              // FLOAT — approximate
$table->double('coord', 15, 8);     // DOUBLE — high-precision approximate

For money, use decimal — floats accumulate rounding errors. For coordinates and physics, double with high precision.

Dates and times

$table->date('birthday');           // DATE
$table->dateTime('starts_at');      // DATETIME
$table->time('opens_at');           // TIME
$table->timestamp('confirmed_at');  // TIMESTAMP
$table->year('graduated');          // YEAR (MySQL-specific)

Booleans, enums, binary

$table->boolean('is_active');                 // TINYINT(1) on MySQL, native BOOLEAN on PG
$table->enum('status', ['draft', 'live']);    // ENUM — MySQL-specific; consider check constraints instead
$table->binary('data');                       // BLOB

Foreign keys (modern form)

// Recommended — single line
$table->foreignId('user_id')->constrained();

// With ON DELETE cascade
$table->foreignId('post_id')
    ->constrained()
    ->cascadeOnDelete();

// Pointing at a non-conventional column
$table->foreignUuid('account_id')
    ->constrained('accounts', 'uuid')
    ->cascadeOnDelete();

// Polymorphic
$table->morphs('taggable');             // adds taggable_id (BIGINT) + taggable_type (VARCHAR)
$table->nullableMorphs('taggable');     // same, but both nullable

Column modifiers

$table->string('email')->nullable();          // allow NULL
$table->integer('count')->default(0);         // default value
$table->integer('age')->unsigned();           // no negative values
$table->string('slug')->unique();             // UNIQUE constraint
$table->string('email')->index();             // index for searching
$table->text('summary')->after('title');      // place after a specific column (MySQL)
$table->string('note')->comment('Internal'); // attach a column comment

Modifiers chain on any column declaration. For schema changes, $table->string('email')->nullable()->change() alters an existing column.

Frequently asked questions

Should I use id() or bigIncrements('id')?

Same column. $table->id() (Laravel 7+) is the modern shortcut — it creates an auto-incrementing unsigned BIGINT primary key named id. bigIncrements('id') is the explicit form. Either works on every modern Laravel; id() reads cleaner.

Why foreignId() instead of unsignedBigInteger?

$table->foreignId('user_id')->constrained() creates the column and the foreign key constraint in one go. Compared to the old pattern of unsignedBigInteger('user_id') followed by foreign('user_id')->references('id')->on('users'), it’s three lines shorter and reads cleanly. Use it for new code; the old form still works.

What’s the difference between timestamps() and timestampsTz()?

timestamps() creates created_at and updated_at as TIMESTAMP columns (UTC seconds since epoch on MySQL). timestampsTz() uses TIMESTAMP WITH TIME ZONE — supported on PostgreSQL, treated as plain timestamp on MySQL. For multi-region apps where you store local times explicitly, use timestampsTz(). For UTC-everywhere apps, the plain version is fine.

Are tinyInteger, smallInteger, etc. worth the column-size optimization?

On disk yes, in practice rarely. The size difference matters when a column holds billions of rows; under millions, the gain is invisible. Pick the type that matches the value range, not the smallest possible — clarity beats premature optimization. For booleans, boolean() generates the right tiny column for your database.

Related guides

  • How to Add Foreign Keys in Laravel Migration
  • How to Add New Columns to an Existing Table in Laravel Migration
  • How to Change a MySQL Column Data Type Using Migration in Laravel

References

Laravel migrations — column types: laravel.com/docs/migrations#available-column-types. Foreign-key constraints: laravel.com/docs/migrations#foreign-key-constraints.

TAGGED:databaseLaravelphp

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Fix Laravel CSRF token mismatch in DataTables Ajax How to Fix Laravel CSRF Token Mismatch in DataTables Ajax
Next Article Fix DKIM not signing emails in aaPanel How to Fix DKIM Not Signing Emails in aaPanel
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

Laravel cURL error 60 SSL certificate problem — CA bundle wiring in php.ini
Web Development

How to Fix cURL Error 60 SSL Certificate Problem in Laravel

9 Min Read
Enable the PHP DOM extension on a Linux server
Server Management

How to Enable the PHP DOM Extension

5 Min Read
Configure WordPress multisite with subdirectories on Nginx — nginx gear + wordpress tree with subsite branches
Web Development

How to Configure WordPress Multisite with Subdirectories on Nginx

12 Min Read
Create a folder in PHP if it does not already exist
Web Development

How to Create a Folder If It Does Not Exist in PHP

5 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?