Supabase Migration Failed? 9 Ways to Fix Database Errors

Supabase migration failed? Bold white title centered on a black background - Primingo
If a Supabase migration failed, locate the first PostgreSQL error, compare local and remote migration versions, and inspect the actual database before retrying. Missing relations, constraint violations, insufficient privileges, and inconsistent migration history require different fixes. Start with supabase migration list and supabase db push --dry-run. Never use migration repair to fix SQL because it only changes migration tracking records.

How Do You Diagnose a Failed Supabase Migration?

Find the failing SQL statement and its SQLSTATE code, then check which migration version Supabase attempted to apply. The code points toward a specific PostgreSQL problem, while migration history shows which files the remote database has recorded. Confirm the linked project before inspecting pending changes, particularly when your team manages development, staging, and production separately.

supabase migration list
supabase db push --dry-run

The first command compares migration timestamps. The second shows which migrations a push would apply, but does not run or validate their SQL. Supabase’s official CLI command reference for migrations, dry runs, and history repair explains these behaviors. Inspect the output before proceeding.

Error or statusMeaningFirst investigationGo to
42P01Undefined relationConfirm schema name and migration orderFix 2
42703Undefined columnInspect column spelling and dependenciesFix 2
42P07Duplicate tableCompare existing object definitionsFix 2
23514CHECK constraint violationFind incompatible recordsFix 3
23505Unique constraint violationIdentify duplicate key valuesFix 3
23503Foreign key violationCheck referenced recordsFix 3
42501Insufficient privilegeConfirm SQL role and ownershipFix 4
History mismatchLocal and remote versions differCompare tracking with schemaFix 5
MIGRATIONS_FAILEDBranch migration replay stoppedInspect workflow and Postgres logsFix 9

Codes such as 23514 and 42P01 come from PostgreSQL. MIGRATIONS_FAILED instead describes a Supabase branch workflow status, so examine the underlying Postgres log for the actual SQL error.

How Do You Fix a Failed Supabase Database Migration?

Correct the cause shown by the error, rather than rerunning the same migration or changing its history blindly. The following nine fixes cover SQL execution, data constraints, database privileges, history mismatches, partial changes, local resets, and branch replay problems. Begin with inspection commands and use production changes only after confirming the database state and recovery options.

1. How Do You Find the Migration File and Failed SQL Statement?

Read the CLI output for the migration filename, the statement PostgreSQL rejected, and its error details. Compare the filename with your local supabase/migrations directory, then verify that the correct project is linked. The last line saying that a command failed is less useful than the first specific SQL error reported above it.

  • Filename: Identify the timestamped SQL file that caused the error.
  • Database target: Check that the linked project is the intended environment.
  • Statement: Locate the exact table, column, function, or constraint involved.
  • History: Compare local files with versions already recorded remotely.

Do not edit a migration that another environment has already applied without reviewing its history. If different environments use different versions of the same file, coordinate a safe correction with the team.

2. How Do You Fix Missing Table, Column, or Duplicate Relation Errors?

Error 42P01 means PostgreSQL cannot find a referenced relation, 42703 indicates an undefined column, and 42P07 means a table name already exists. Inspect schema names, dependency order, and previously applied migrations. These problems often arise when a migration assumes an object was created earlier or tries to recreate an object already present.

Use a read-only catalog query to check whether the expected table exists in a different schema. Replace the sample table name with the object named in your error.

SELECT table_schema, table_name
FROM information_schema.tables
WHERE table_name = 'orders';

If the object exists, compare its actual definition with the migration before adding IF NOT EXISTS. Suppressing a duplicate error without checking the existing structure can conceal an incompatible table or column definition.

3. How Do You Fix Supabase CHECK, Unique, and Foreign Key Constraint Errors?

Constraint errors mean the proposed schema change conflicts with existing data or an integrity rule. PostgreSQL uses 23514 for CHECK violations, 23505 for unique violations, and 23503 for foreign key violations. Identify the affected constraint and the records involved before updating data, relaxing restrictions, or applying the migration again.

  • CHECK violation: Find values that do not satisfy the new rule.
  • Unique violation: Identify duplicate values before adding a unique constraint or index.
  • Foreign key violation: Confirm referenced rows exist and review intended deletion behavior.

For suitable CHECK constraints, PostgreSQL can add a rule using NOT VALID and validate existing data later. The rule still applies to new or updated rows. Review the specific constraint and deployment plan before using staged validation on a production table.

4. How Do You Fix Supabase Migration Permission Denied Errors?

PostgreSQL error 42501 indicates that the role executing a statement lacks permission for the requested operation. Check the connected role, object ownership, schema privileges, and the exact SQL statement. Reading a table does not automatically grant permission to alter it. Avoid broad grants that expose more database access than the operation requires.

A migration privilege error is different from an application request denied by Row Level Security. If the migration succeeds but users still receive authorization errors, see Supabase RLS Policy Error to diagnose grants, policies, and authentication separately.

5. How Do You Resolve Local and Remote Migration History Mismatches?

A history mismatch occurs when migration timestamps in local files differ from entries in supabase_migrations.schema_migrations. Schema drift is different: the database structure itself no longer matches the structure that the migration files describe. Supabase compares migration versions, not every table definition, so inspect both the recorded history and actual objects before reconciling them.

Observed stateWhat it suggestsSafe next step
Remote version has no local fileA migration file may be missing from GitRecover the correct file or inspect migration fetch
Schema changed but history has no versionHistory may be incompleteVerify all SQL effects before repairing
History says applied but objects are missingTracking may be incorrect or changes were reversedInspect objects before considering reverted
Objects differ despite matching versionsSchema drift may existReview manual edits and a controlled db pull

supabase migration fetch can recover available SQL files stored in migration history. supabase db pull captures schema differences into a new local migration. Review generated SQL carefully, keep the repository history intact, and do not delete migration files as a shortcut.

6. When Should You Use Supabase Migration Repair?

Use supabase migration repair only when you have verified that migration tracking records do not reflect the database’s actual state. Marking a version applied inserts a history record, while marking it reverted removes that record. Neither operation creates tables, executes pending SQL, or undoes a committed schema change.

Choose one of the following alternatives only after confirming the correct migration timestamp and database state. The commands must not be run together as a general repair procedure.

# Use only if the complete migration effect already exists
# but its history record is missing.
supabase migration repair TIMESTAMP --status applied
# Use only if history incorrectly records a migration
# that was never applied.
supabase migration repair TIMESTAMP --status reverted

When only part of the intended change exists, reconcile the schema before modifying history. An incorrect record can cause future pushes to skip necessary SQL or attempt objects that already exist.

7. How Do You Recover a Supabase Migration That Partially Applied?

Inspect the actual tables and data because a failed migration can leave earlier statements committed when execution crosses transaction boundaries. Explicit BEGIN and COMMIT statements can interrupt the migration runner’s usual transaction handling. Some pg-delta migrations also use a directive to run without a wrapping transaction, allowing earlier statements to persist after a later error.

-- pg-delta: transaction=false

Supabase’s local development guidance says supported CLI operations honor this directive. Confirm which statements already succeeded, then prepare a reviewed cleanup or recovery migration. Do not rerun the original SQL or drop objects until you know whether an earlier step affected production data.

8. How Do You Fix Supabase DB Reset Failed?

If supabase db reset fails while replaying migrations, identify the first broken SQL file and correct its dependencies. A different failure can occur when the local Docker or database environment cannot start. The ordinary local reset recreates local database state and reapplies migration files, so preserve development data that your migrations and seed files cannot reproduce.

# Local development only. Recreates the local database.
supabase db reset

First verify that your local Supabase stack is running. Do not add --linked or --db-url simply to fix a local reset error. Those flags can target a remote database and have destructive consequences.

9. How Do You Fix MIGRATIONS_FAILED on a Supabase Branch?

A branch can show MIGRATIONS_FAILED when Supabase cannot replay migration history against its database. Open the affected branch’s workflow logs, identify the unsuccessful migration step, then inspect Postgres logs for the underlying statement. Missing dependencies, schema drift, and transaction requirements may cause branch replay to fail even when the primary project works.

Supabase’s GitHub branching integration runs migration files inside transactions and does not honor -- pg-delta: transaction=false. A migration that works with supabase db push may therefore fail during branching if its SQL requires execution outside a transaction, such as CREATE INDEX CONCURRENTLY.

How Do You Document a Supabase Branch Migration Error for Your Team?

Record the failing branch, exact migration version, workflow status, and Postgres error before sending the problem to another developer. Include the SQL file and a safe description of the expected schema. If the problem only appears while using the Dashboard, show the sequence of actions without exposing database credentials or private records.

For a visual reproduction, How to Use Jam for Bug Reporting explains how to capture the Dashboard issue. Pair the recording with the actual SQL error and migration history, because a screen capture cannot identify the database cause by itself.

How Can You Prevent Supabase Migration Failures in Production?

Test the full migration sequence before deploying, confirm the target environment, and preserve a recoverable database state. Keep SQL migration files in version control, test constraints against realistic data, and coordinate schema changes across teammates. A successful dry run only identifies pending files; it cannot establish whether the SQL will execute safely.

  • Confirm the intended Supabase project and credentials before running deployment commands.
  • Test migrations with local replay and representative existing records.
  • Review constraints, ownership requirements, and dependencies between migration files.
  • Check backup coverage and practice restoration before destructive changes.
  • Verify the final tables, columns, and migration history after deployment.

If your production project requires paid Supabase features, review its eligibility and backup requirements independently of the SQL fix. The Supabase Pro subscription options on Primingo provide a third-party purchasing option. Confirm access and product terms before buying; a subscription cannot resolve a broken migration.

What Backup and Recovery Checks Matter Before a Supabase Migration?

Confirm that a usable backup exists and that your team knows how to restore it before applying a migration that could change or remove data. Review the affected tables, estimate how long restoration might take, and document which application writes must pause during recovery. A backup is not a proven recovery plan until you have tested its restoration procedure.

Backup availability and recovery features can vary by plan and configuration. For a separate cost comparison, Supabase Pricing 2026: Plans, Costs, Free Tier and Pro Pricing explains the plan differences. Choose the technical recovery method based on your database state, not on a purchase recommendation.

When Should You Contact Support About a Supabase Migration Error?

Escalate when you cannot establish which statements ran, when a production database may contain partial changes, or when repeatable branch failures persist after verifying the migration sequence. Preserve the filename, SQLSTATE code, statement, CLI version, target environment, migration history, and relevant logs. Remove passwords, connection strings, and customer data before sharing diagnostic evidence.

For recurring browser-based Dashboard problems, a recorded reproduction can complement the database evidence. Teams that need collaborative visual reports can review the Jam Team bug reporting subscription on Primingo. This is an optional reporting tool, not a migration repair service or a substitute for SQL logs.

How Do You Confirm a Supabase Migration Was Recovered Correctly?

Verify the intended schema, inspect migration tracking, and test the application operations that depend on the changed objects. A command reporting success does not establish that data, permissions, and dependent application behavior all remain correct. Confirm that the expected tables and constraints exist and that no unexpected changes appeared in production.

Teams that source other developer subscriptions through the Primingo subscriptions should handle purchase or account questions separately from database recovery. The Supabase CLI, the database state, and technical support remain the primary sources for resolving migration execution problems.

Frequently Asked Questions About Supabase Migration Errors

These answers address the common decisions that follow a failed database migration, including whether retrying is safe, what history repair changes, and how to interpret an absent tracking table. Each question concerns a different outcome. Always match the reported status to the current database state before performing a command that changes schema or data.

Can You Safely Rerun a Failed Supabase Migration?

Yes, but only after fixing the underlying error and checking for committed partial changes. A previous attempt might have already created tables, columns, or indexes. Running the original SQL again can produce duplicate object errors or inconsistent data. Reconcile the actual schema and test the corrected migration before another production push.

Does Supabase Migration Repair Change Database Tables?

No. supabase migration repair updates migration tracking records rather than executing SQL or rolling back tables. Marking a version applied does not create its schema objects. Marking it reverted does not drop them. Use repair only when the actual schema is understood and the history record is demonstrably incorrect.

Why Does Supabase Say schema_migrations Does Not Exist?

The migration tracking table may not exist because the Supabase CLI has not initialized that database’s migration history. Supabase Dashboard background checks can report this even when no application deployment has failed. If your project uses CLI migrations, review pending files before initializing tracking because supabase db push can apply real schema changes.

Why Does a Supabase Migration Appear Applied After It Failed?

The tracking record or some schema changes may have persisted even though a later statement reported an error. Compare supabase_migrations.schema_migrations with the real tables, columns, and constraints. An unsuccessful status alone cannot tell you which statements committed. Confirm the transaction boundaries before considering a history repair or rerun.

Can a Failed Supabase Migration Cause Data Loss?

A failed migration does not automatically erase data, but destructive SQL and unsafe recovery actions can affect existing records. Statements that committed before a later error may also remain in place. Inspect the executed SQL, review affected rows, and verify backup restoration options before running cleanup commands against a production database.

Chat with us