Database Laravel 8 Laravel 9 Laravel 10 Laravel 11 Laravel 12

Migration Failed in Laravel - How to Debug and Fix

This error occurs when running migrations fails due to various database or migration file issues.

The Error

Error Message
Migration table not found / Migration failed

Common Causes

  1. 1 Database connection issues
  2. 2 Migration syntax errors
  3. 3 Table already exists
  4. 4 Foreign key constraint issues
  5. 5 Migration run in wrong order

Solutions

1

Check migration status

Bash
# See which migrations have run
php artisan migrate:status

# Rollback last batch
php artisan migrate:rollback

# Rollback specific steps
php artisan migrate:rollback --step=2
2

Reset and re-run all migrations (dev only)

Bash
# WARNING: This drops all tables!
php artisan migrate:fresh

# With seeders
php artisan migrate:fresh --seed
3

Fix foreign key order issues

PHP
// Rename migration files to control order
// 2024_01_01_000001_create_users_table.php
// 2024_01_01_000002_create_posts_table.php

// Or disable foreign key checks temporarily
Schema::disableForeignKeyConstraints();
Schema::dropIfExists('posts');
Schema::enableForeignKeyConstraints();
4

Add existence check in migration

PHP
public function up()
{
    if (!Schema::hasTable('posts')) {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->timestamps();
        });
    }
}

Need Help With Your Laravel Project?

I specialize in building custom Laravel applications, process automation, and SaaS development. Whether you need to eliminate repetitive tasks or build something from scratch, let's discuss your project.

Currently available for 2-3 new projects

Hafiz Riaz

About Hafiz

Full Stack Developer from Italy. I build web applications with Laravel and Vue.js, and automate business processes. Creator of ReplyGenius, StudyLab, and other SaaS products.

View Portfolio

Related Errors