#25312: Bug: AutoField backed by Postgres 9+ creates error condition ------------------------------+-------------------------------------------- Reporter: infintesimal | Owner: nobody Type: Bug | Status: new Component: | Version: 1.7 Uncategorized | Severity: Normal | Keywords: AutoField, Postgres, Sequences Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 ------------------------------+-------------------------------------------- The essence of this bug report is that models.py creates an inherent conflict between default, autoincrementing id fields (AutoField) and what a postgres 9.x (9.4 in my case) assigns as the type for the auto incrementing field. When makemigration creates the sequence, the sequence is created as a big integer. However, the database table that uses the sequence (the id field) is created as an integer. So once the value of the sequence exceeds the maximum value of a 32 bit integer, the insert will fail.
Below is models.py code and some psql command line foo to illustrate the problem {{{ import datetime import hashlib import os from math import sqrt from random import Random from django.db import models from django.db.models.query import Q from django.utils.text import slugify from djangoratings.fields import RatingField from django_pgjson.fields import JsonBField from django_images.models import Image as BaseImage from django.utils import timezone class EventName(models.Model): event_name = models.CharField(max_length=500, blank=False, null=False) event_desc = models.CharField(max_length=500, blank=False, null=True) event_creation_date = models.DateTimeField(auto_now_add=True,null=False) event_update_date = models.DateTimeField(auto_now=True,null=False) def __unicode__(self): return self.name }}} {{{ steves_app=> \d eventlogs_eventname_id_seq Sequence "public.eventlogs_eventname_id_seq" Column | Type | Value ---------------+---------+---------------------------- sequence_name | name | eventlogs_eventname_id_seq last_value | bigint | 1 start_value | bigint | 1 increment_by | bigint | 1 max_value | bigint | 9223372036854775807 min_value | bigint | 1 cache_value | bigint | 1 log_cnt | bigint | 0 is_cycled | boolean | f is_called | boolean | f Owned by: public.eventlogs_eventname.id steves_app=> \d eventlogs_eventname Table "public.eventlogs_eventname" Column | Type | Modifiers ---------------------+--------------------------+------------------------------------------------------------------ id | integer | not null default nextval('eventlogs_eventname_id_seq'::regclass) event_name | character varying(500) | not null event_desc | character varying(500) | event_creation_date | timestamp with time zone | not null event_update_date | timestamp with time zone | not null Indexes: "eventlogs_eventname_pkey" PRIMARY KEY, btree (id) Referenced by: TABLE "eventlogs_event" CONSTRAINT "eventlog_event_id_id_153f5722b6e1dffb_fk_eventlogs_eventname_id" FOREIGN KEY (event_id_id) REFERENCES eventlogs_eventname(id) DEFERRABLE INITIALLY DEFERRED fitcode_app=> alter sequence eventlogs_eventname_id_seq restart with 4294967297; ALTER SEQUENCE fitcode_app=> insert into eventlogs_eventname(event_name,event_desc,event_creation_date,event_update_date) values ('foo','bar',now(),now()); ERROR: integer out of range }}} -- Ticket URL: <https://code.djangoproject.com/ticket/25312> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/055.6ee7c378ac0107a29ca924a85f3cd785%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.