Opened 14 years ago
Closed 9 years ago
#14286 closed New feature (fixed)
Support for BigAutoField
Reported by: | hongrich | Owned by: | mmcnickle |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Michael, Sergey Kolosov, ethan.jucovy@…, ludo@…, stodge@…, cmawebsite@…, Nicola, samir, mike@…, marti@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
1.2 added BigIntegerField, but there is still no support for using bigint as auto increment primary key. Could there be an official version of BigAutoField?
Reference of various attempts over the years:
http://djangosnippets.org/snippets/1244/
Attachments (2)
Change History (42)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Of course, this can be easily handled as an external field definition, but given that BigInteger is in trunk, I suppose it makes sense for there to be a BigAutoField too.
comment:3 by , 14 years ago
Owner: | changed from | to
---|
by , 14 years ago
Attachment: | 14286-Add_BigAutoField.diff added |
---|
Adds BigAutoField as a new field type, with documentation.
comment:4 by , 14 years ago
Has patch: | set |
---|---|
Needs tests: | set |
Version: | 1.2 → SVN |
comment:5 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:6 by , 13 years ago
Easy pickings: | unset |
---|---|
UI/UX: | unset |
Hello guys,
Since 1.4 is to be released soon™, could this feature be integrated into it? I looked in the trunk and did not find it. It shouldn't have much impact on anything.
I could perform the integration of the patch proposed by mmcnickle, but since I'm new here, I'm not sure if I can :)
Thanks!!! Django is a wonderfull piece of software o/
comment:7 by , 13 years ago
Cc: | added |
---|
comment:8 by , 13 years ago
Cc: | added |
---|
comment:9 by , 13 years ago
#18201 asked for tinyint and smallint based AutoFields
. If bigint based fields is added in this ticket, it would make sense to add smallint based AutoField, too.
comment:10 by , 12 years ago
Cc: | added |
---|
follow-up: 17 comment:12 by , 12 years ago
This week we upgraded to from 1.3 -> 1.5, and discovered BigAutoField was not yet included in Django. I know this issue has been referenced in a number of tickets over the years. In Django 1.3, we went with the mmcnickle approach discussed in this ticket, but found this difficult to merge into 1.5.
This time, we went with the approach approach suggested by pzinovkin in ticket 56 (https://code.djangoproject.com/attachment/ticket/56/56_bigint.diff). It required tweaking to get it to work cleanly with 1.5
Attached are patches derived from a git clone this morning.
comment:13 by , 12 years ago
What needs to be done to move this patch to completion and integration?
comment:16 by , 11 years ago
Cc: | added |
---|
comment:17 by , 11 years ago
Replying to jamercee:
This week we upgraded to from 1.3 -> 1.5, and discovered BigAutoField was not yet included in Django. I know this issue has been referenced in a number of tickets over the years. In Django 1.3, we went with the mmcnickle approach discussed in this ticket, but found this difficult to merge into 1.5.
This time, we went with the approach approach suggested by pzinovkin in ticket 56 (https://code.djangoproject.com/attachment/ticket/56/56_bigint.diff). It required tweaking to get it to work cleanly with 1.5
Attached are patches derived from a git clone this morning.
I tried to apply the patch to my 1.5 Django release:
patch -p1 --dry-run -r /var/tmp/reject.txt < bigauto.diff
patching file django/db/backends/init.py
Hunk #1 succeeded at 901 (offset -154 lines).
patching file django/db/backends/mysql/creation.py
Hunk #1 FAILED at 7.
1 out of 1 hunk FAILED -- saving rejects to file /var/tmp/reject.txt
patching file django/db/backends/oracle/creation.py
Hunk #1 FAILED at 17.
1 out of 1 hunk FAILED -- saving rejects to file /var/tmp/reject.txt
patching file django/db/backends/postgresql_psycopg2/creation.py
Hunk #1 FAILED at 11.
1 out of 1 hunk FAILED -- saving rejects to file /var/tmp/reject.txt
patching file django/db/backends/sqlite3/base.py
Hunk #1 succeeded at 214 (offset -34 lines).
patching file django/db/backends/sqlite3/creation.py
Hunk #1 FAILED at 9.
1 out of 1 hunk FAILED -- saving rejects to file /var/tmp/reject.txt
patching file django/db/models/fields/init.py
Hunk #1 succeeded at 213 (offset -2 lines).
Hunk #2 succeeded at 240 (offset -2 lines).
Hunk #3 succeeded at 531 (offset -8 lines).
Hunk #4 succeeded at 1158 (offset -8 lines).
Hunk #5 succeeded at 1174 (offset -8 lines).
patching file django/db/models/fields/related.py
Hunk #1 succeeded at 1092 (offset -21 lines).
patching file docs/ref/models/fields.txt
Hunk #1 FAILED at 331.
1 out of 1 hunk FAILED -- saving rejects to file /var/tmp/reject.txt
The version of Django is 1.5.0. Could someone tell me what am I doing wrong ?
Thanks,
Jorge
comment:18 by , 10 years ago
Has there been any progress on this ticket? Is there a chance it will be included (and back-ported to 1.6)?
comment:19 by , 10 years ago
Cc: | added |
---|
comment:20 by , 10 years ago
I don't see any progress. It would be included in Django 1.8 at the earliest. You can read about our support versions policy.
comment:21 by , 10 years ago
I have patches for 1.6 and 1.7 ATM in my django fork:
Commit (patch) for 1.6: https://github.com/skirsdeda/django/commit/089fc7f165fb6cb7eb851b81a44660a986797946
Commit (patch) for 1.7: https://github.com/skirsdeda/django/commit/b0a567cc3fa7083ddcdca4f291b1e6d7fa85f6c7
It seems db backend implementation is changed a bit in master branch, so more work is needed. But I'm planning to do this sometime soonish.
comment:22 by , 10 years ago
What needs done to make this happen?
It's pretty painful to modify these kinds of things currently and Sentry hit BIGINT quite a while back.
I'm attempting to hack this up but these are pretty deep internals and while I haven't given up I've yet to make things work.
Specifically the primary issue right now that we've hit with just doing it externally is with foreign keys:
https://github.com/getsentry/sentry/issues/1354#issuecomment-68393116
follow-up: 25 comment:23 by , 10 years ago
In fact, I'd propose a new API be added to keys: "get_related_db_type" (or something along these lines)
I'm implement a custom ForeignKey locally that will do this, and allow BigAutoField to return BigIntegerField().db_type(connection)
comment:24 by , 10 years ago
Related, here's our terrible solution to this in Sentry:
https://github.com/getsentry/sentry/commit/f34cf31dd31633910daa3fb992e933e5fd62911f
Specifically..
comment:25 by , 10 years ago
Replying to dcramer:
In fact, I'd propose a new API be added to keys: "get_related_db_type" (or something along these lines)
Yes please. Currently, ForeignKey.db_type is too tightly coupled to AutoField and IntegerField. There should be a new method that ForeignKey can call to ask the related field what SQL should be used to create a foreign key to that type. BitAutoField would return 'bigint'. AutoField would return a regular int. Most fields would simply defer to what db_type already returns.
Someone has already submitted this: #13774
comment:26 by , 10 years ago
Cc: | added |
---|
comment:27 by , 10 years ago
Cc: | added |
---|
comment:29 by , 9 years ago
Cc: | added |
---|
comment:30 by , 9 years ago
Cc: | added |
---|
comment:31 by , 9 years ago
Cc: | added |
---|
comment:32 by , 9 years ago
Needs tests: | unset |
---|
comment:33 by , 9 years ago
Triage Stage: | Accepted → Unreviewed |
---|
comment:34 by , 9 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
comment:35 by , 9 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
Sorry, but you are not supposed to mark your own patches as RFC.
comment:36 by , 9 years ago
Patch needs improvement: | set |
---|
Added some comments for improvement on the pull request.
comment:37 by , 9 years ago
Patch needs improvement: | unset |
---|
comment:38 by , 9 years ago
Patch needs improvement: | set |
---|
I left another round of mostly cosmetic comments, looks like it's almost there.
In the meantime, it suffices to use a standard
AutoField
and hack the database like so:In the table in question, alter the field like so:
ALTER TABLE [table_name] ALTER COLUMN [field_name] [data_type]
, where[data_type]
is one of the following:MySQL:
bigint AUTO_INCREMENT
Oracle:
NUMBER(19)
PostgreSQL:
bigserial
SQLite:
integer
For every foreign key pointing to your field, you will also need to alter the column, but with these data types:
MySQL:
bigint
Oracle:
NUMBER(19)
PostgreSQL:
bigint
SQLite:
integer
This is a pain, but you only need to do it when creating tables, once. On the other hand, users shouldn't have to hack the database for such a simple feature, in my opinion. It would be super-cool if 1.3 included a fully-functional
BigAutoField
.