3077
MySQLERRORNotableSchemaHIGH confidence

Spatial index must be on a geometry column

Production Risk

Low — DDL fails with an error; no data is modified.

What this means

A SPATIAL index can only be created on a column with a geometry data type.

Why it happens
  1. 1Attempting to create a SPATIAL INDEX on a non-geometry column (e.g., INT, VARCHAR).
How to reproduce
trigger — this will error
trigger — this will error
CREATE TABLE t (id INT, name VARCHAR(100), SPATIAL INDEX(name));

expected output

ERROR 3077 (HY000): A SPATIAL index may only contain a geometrical type column.

Fix

Use a geometry column for spatial indexing

Use a geometry column for spatial indexing
CREATE TABLE t (id INT, location POINT NOT NULL SRID 4326, SPATIAL INDEX(location));

Why this works

SPATIAL indexes require geometry-typed columns.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3077 ER_SPATIAL_MUST_HAVE_GEOM_COL2

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors