Out of Range Table
I looked into a problem that occurred recently when adding observations to the spectra
table over break. The error message was
DataError: (1264, u"Out of range value for column 'spec_id' at row 305")
This was due to using a normal INT
type for the index. The fix is quite simple in MySQL, you can change the type using the command:
ALTER TABLE table_name MODIFY column_name BIGINT;
However, spec_id
is also auto incrementing and the PRIMARY KEY for
my table. Here is the description of spec_id
BEFORE ALTERing the
TABLE:
mysql> describe spectra;
+----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+----------------+
| spec_id | int(11) | NO | PRI | NULL | auto_increment |
Since there is already a PRIMARY KEY set (spec_id), MySQL will produce an
error if PRIMARY KEY is specified when attempting to MODIFY the TABLE.
Fortunately, this does not matter — the spec_id column will
remain the primary key even if PRIMARY KEY is not specified. However, AUTO_INCREMENT
does need to be specified when altering the column.
ALTER TABLE table_name MODIFY column_name BIGINT AUTO_INCREMENT;
In my specific case the command used to change my MySQL column
from an INT
type to BIGINT
was
ALTER TABLE spectra MODIFY spec_id BIGINT AUTO_INCREMENT;
which resulted in
mysql> describe spectra;
+------------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------+------+-----+---------+----------------+
| spec_id | bigint(20) | NO | PRI | NULL | auto_increment |
Using BIGINT
for the type will allow for up to 9 Quadrillion rows in the table! That should last for a while.