phacility/phabricator · error · AphrontSchemaQueryException

1146, 1049, 1054

1146, 1049, 1054

Error message

#%d: %s

What it means

MySQL reported a missing schema object while running a query: 1146 (table doesn't exist), 1049 (database doesn't exist), or 1054 (unknown column). These are mapped to AphrontSchemaQueryException because in Phabricator they almost always mean the running code expects a newer schema than the database has. The database name itself may also be wrong (namespace mismatch), producing 1049.

Source

Thrown at src/infrastructure/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php:366

      case 1142: // Access denied to table
      case 1143: // Access denied to column
      case 1227: // Access denied (e.g., no SUPER for SHOW SLAVE STATUS).

        // See T13622. Try to help users figure out that this is a GRANT
        // problem.

        $more = pht(
          'This error usually indicates that you need to "GRANT" the '.
          'MySQL user additional permissions. See "GRANT" in the MySQL '.
          'manual for help.');

        throw new AphrontAccessDeniedQueryException("{$message}\n\n{$more}");
      case 1045: // Access denied (auth)
        throw new AphrontInvalidCredentialsQueryException($message);
      case 1146: // No such table
      case 1049: // No such database
      case 1054: // Unknown column "..." in field list
        throw new AphrontSchemaQueryException($message);
    }

    // TODO: 1064 is syntax error, and quite terrible in production.

    return null;
  }

  protected function throwConnectionException($errno, $error, $user, $host) {
    $this->throwCommonException($errno, $error);

    $message = pht(
      'Attempt to connect to %s@%s failed with error #%d: %s.',
      $user,
      $host,
      $errno,
      $error);

    throw new AphrontConnectionQueryException($message, $errno);

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Apply pending schema patches: phabricator/bin/storage upgrade (check bin/storage status first)
  2. Verify the namespace and database configuration: storage.default-namespace, mysql.host, and cluster.databases must all resolve to the database you actually initialized
  3. Inspect what exists: phabricator/bin/storage databases / status to see whether the expected tables and columns are present
  4. If a custom patch references the column, either land its storage patch or remove the reference

Example fix

# before: new code deployed, old schema
svn up phabricator/ && restart_phabricator
# => AphrontSchemaQueryException: #1054 Unknown column ...

# after: upgrade storage as part of every deploy
svn up phabricator/
phabricator/bin/storage upgrade --force  # or without --force after review
restart_phabricator
Defensive patterns

Strategy: validation

Validate before calling

// Deploy gate: refuse to serve traffic on a stale schema.
// phabricator/bin/storage status   -> must show no unapplied patches
// phabricator/bin/storage upgrade  -> apply, before switching traffic
// Then verify namespace/database resolution:
// phabricator/bin/config get storage.default-namespace

Try / catch

try {
  $rows = queryfx_all($conn_r, '...');
} catch (AphrontSchemaQueryException $ex) {
  // Code newer than schema: trigger an out-of-band 'storage upgrade needed'
  // alert instead of letting raw 1146/1054 errors reach users.
}

Prevention

When it happens

Trigger: Running new code that queries a table/column introduced by an unapplied storage patch; storage.default-namespace resolving to a different database name than the one that was initialized; a partially applied or interrupted bin/storage upgrade; an extension or fork referencing a column that never existed in this tree.

Common situations: Deploying a new Phabricator version without running bin/storage upgrade first; pointing a test install at a namespace initialized long ago; restoring a dump into a differently-named database; third-party patches assuming schema changes that were reverted.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/bd6e14bb808fbb2d. Report an issue: GitHub.