From 8615a9e6ea0c811aee2884a8a9fc2fb5a6ca6a96 Mon Sep 17 00:00:00 2001 From: Shung-Hsi Yu <6041291+shunghsiyu@users.noreply.github.com> Date: Sun, 12 Jul 2020 17:10:20 +0800 Subject: [PATCH] Use BigAutoField for User.id We have been using the bigint data type for User.id since ab2573d6a25a, but the id field that Django automatically create for us uses AutoField, which maps to the int data type. This mismatch in data type is mostly benign, but when User.id grow large enough, it will blowup when we try to use setval on User.id (e.g. importing fixture with `manage.py loaddata`), with an error complaining value out of range. --- .../migrations/0012_auto_20200712_1632.py | 18 ++++++++++++++++++ src/users/models.py | 1 + 2 files changed, 19 insertions(+) create mode 100644 src/users/migrations/0012_auto_20200712_1632.py diff --git a/src/users/migrations/0012_auto_20200712_1632.py b/src/users/migrations/0012_auto_20200712_1632.py new file mode 100644 index 000000000..aa37d1758 --- /dev/null +++ b/src/users/migrations/0012_auto_20200712_1632.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.3 on 2020-07-12 08:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0011_cocrecord_agreed_at'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='id', + field=models.BigAutoField(primary_key=True, serialize=False), + ), + ] diff --git a/src/users/models.py b/src/users/models.py index b9a094dc9..48dd451ba 100644 --- a/src/users/models.py +++ b/src/users/models.py @@ -108,6 +108,7 @@ def photo_upload_to(instance, filename): class User(AbstractBaseUser, PermissionsMixin): + id = models.BigAutoField(primary_key=True) email = models.EmailField( verbose_name=_('email address'), max_length=255, unique=True, db_index=True,