対応方法 When MySQL AutoIncrement Runs Out

Django
2020-05-18 11:16 (4 years ago) ytyng
MySQLdb._exceptions.OperationalError: (1467, 'Failed to read auto-increment value from storage engine')


In Django, when you specify an implicit id, the above error occurs if the auto increment value reaches its upper limit.

Checking the database:

SELECT AUTO_INCREMENT
FROM information_schema.tables
WHERE TABLE_SCHEMA = 'my_schema'
AND TABLE_NAME = 'my_table';
AUTO_INCREMENT
2147483647

SHOW CREATE TABLE my_table;

CREATE TABLE `my_table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
...

Modifying the model:

id = models.BigAutoField(primary_key=True)

Adding the above line

./manage.py makemigrations
./manage.py migrate
SHOW CREATE TABLE my_table;

CREATE TABLE `my_table` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
...

Currently unrated

Comments

Archive

2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011