対応方法 When MySQL AutoIncrement Runs Out

Django
2020-05-18 02:16 (5 years ago)
対応方法 When MySQL AutoIncrement Runs Out
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,
...

Please rate this article
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.

Categories

Archive