# Laravel: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists

**Code:** `Base table or view already exists` · **Category:** Laravel · **Seen on:** Laravel, PHP, MySQL

A migration tries to create a table that is already in the database.

## Meaning

Usually the table was created manually or a previous migration run failed midway (MySQL DDL isn't transactional), leaving a table with no migration record. Fix by dropping the table (dev only) and re-running, adding `Schema::hasTable` checks, or inserting the migration record. Use `migrate:fresh` only on dev data.

## Common causes

- Table created manually or by a failed earlier migration
- Migrations table out of sync
- Duplicate migration files for the same table
- Restored DB dump without the migrations table data
- Running `migrate` against the wrong database

## Quick fix

1. Dev: `php artisan migrate:fresh`
2. Prod: add `if (!Schema::hasTable('users'))` guard or insert the row into `migrations`
3. Check `php artisan migrate:status`

## Detailed fix by platform

### Laravel

1. `php artisan migrate:status` ; dev only: `php artisan migrate:fresh --seed`

## How to diagnose

1. **Table** — Exists already?
2. **Status** — migration recorded?
3. **DB** — Right one?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/laravel/migration-base-table-already-exists)
