medusajs/medusa · error · MedusaError

42703

42703

Error message

${userFriendlyMessage ?? err.message}

What it means

PostgreSQL error 42703 (undefined_column) was raised by the database and re-thrown by Medusa's dbErrorMapper as a MedusaError of type INVALID_DATA. It means a query referenced a column that does not exist on the table, usually because the entity/model field name does not match the actual database schema (missing migration, renamed field, or a typo in a filter/selection). The mapper extracts the offending 'column ...' fragment from the raw driver message to surface it to you.

Solutions

  1. Read the extracted 'column "x" ...' fragment and check whether that column exists in the table (\d table in psql) — then fix the field name in your query/filter to the real column name.
  2. If the column is legitimately part of a new/changed model, generate the module migration (cd packages/modules/<module> && yarn migration:create) and run migrations so the schema matches the entities.
  3. Verify you are passing database field names (snake_case columns) where raw filters require them, not camelCase model properties.
  4. Ensure your database is migrated to the version of @medusajs/* packages your app runs (medusa db:migrate or the framework migration command).

Example fix

// before
await manager.find(Product, {
  where: { material_col: "wood" }, // column "material_col" does not exist
})

// after
await manager.find(Product, {
  where: { material: "wood" }, // matches the actual column defined by the model/migration
})
Defensive patterns

Strategy: try-catch

Type guard

import { MedusaError } from "@medusajs/framework/utils"

function isInvalidDataError(err: unknown): err is MedusaError {
  return err instanceof MedusaError && err.type === MedusaError.Types.INVALID_DATA
}

Try / catch

try {
  await repo.find(filters)
} catch (err) {
  if (err instanceof MedusaError && err.type === MedusaError.Types.INVALID_DATA) {
    // inspect message for 'column "x" does not exist'; surface a field-level error
  }
  throw err
}

Prevention

When it happens

Trigger: Any repository/service operation (find, list, update, upsert, softDelete) that filters on, selects, or orders by a field whose column is absent from the table: e.g. productService.list({ where: { tag_col: x } }) when the column is tag_col_name, or after adding a new property to a model without running its migration.

Common situations: Adding/removing/renaming a data model property in packages/modules/* without generating and running the migration; passing internal/aliased property names instead of actual column names in raw filters; environment database out of sync with the code version; selecting a column dropped in a newer Medusa release.

Related errors


AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27). Data as JSON: /api/errors/4c575e69cbc20ac8. Report an issue: GitHub.

Appendix: source

Thrown at packages/core/utils/src/dal/mikro-orm/db-error-mapper.ts:60

  if (
    err instanceof NotNullConstraintViolationException ||
    (err as any).code === "23502"
  ) {
    throw new MedusaError(
      MedusaError.Types.INVALID_DATA,
      `Cannot set field '${(err as any).column}' of ${upperCaseFirst(
        (err as any).table.split("_").join(" ")
      )} to null`
    )
  }

  if (
    err instanceof InvalidFieldNameException ||
    (err as any).code === "42703"
  ) {
    const userFriendlyMessage = err.message.match(/(column.*)/)?.[0]
    throw new MedusaError(
      MedusaError.Types.INVALID_DATA,
      userFriendlyMessage ?? err.message
    )
  }

  if (
    err instanceof ForeignKeyConstraintViolationException ||
    (err as any).code === "23503"
  ) {
    const info = getConstraintInfo(err)
    throw new MedusaError(
      MedusaError.Types.NOT_FOUND,
      `You tried to set relationship ${info?.keys.map(
        (key, i) => `${key}: ${info.values[i]}`
      )}, but such entity does not exist`
    )
  }

View on GitHub (pinned to 5e06e544a2)