MySQL の AutoIncrement が足りなくなった場合の対応

投稿者: ytyng 3 年, 10 ヶ月 前
MySQLdb._exceptions.OperationalError: (1467, 'Failed to read auto-increment value from storage engine')


Django で、暗黙の id を指定していると、auto increment 値が上限値に達したとき上記のエラーが出る。

DBの確認

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,
...

モデルの修正

id = models.BigAutoField(primary_key=True)

を追加

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

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

現在未評価

コメント

アーカイブ

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