Nice working solution to make up for the absence of BigAutoField in django (#14286).
Project description
Django BigAuto Hack
===================
`Support for BigAutoField <https://code.djangoproject.com/ticket/14286>`_ has been a work in progress for 4 years now. But the ticket has the following valuable comment:
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.
This simple django app makes this hack less of pain. Running
::
$ python manage.py bigautohack myapp.MyModel
Will run the needed ``ALTER TABLE`` commands, turning the database column for ``MyModel``'s primary key into a big integer, as well as all columns referencing ``MyModel``.
To install simply run ``pip install django-bigautohack`` and add ``bigautohack`` to your ``INSTALLED_APPS``.
Limitation
==========
You probably need to make generic foreign keys use a big integer as well.
===================
`Support for BigAutoField <https://code.djangoproject.com/ticket/14286>`_ has been a work in progress for 4 years now. But the ticket has the following valuable comment:
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.
This simple django app makes this hack less of pain. Running
::
$ python manage.py bigautohack myapp.MyModel
Will run the needed ``ALTER TABLE`` commands, turning the database column for ``MyModel``'s primary key into a big integer, as well as all columns referencing ``MyModel``.
To install simply run ``pip install django-bigautohack`` and add ``bigautohack`` to your ``INSTALLED_APPS``.
Limitation
==========
You probably need to make generic foreign keys use a big integer as well.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-bigautohack-0.1.tar.gz
.
File metadata
- Download URL: django-bigautohack-0.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
dab4267670b7563d77f916b96bd58488aa894cc325f9912949fa3b337e6afbd0
|
|
MD5 |
d00d5aaefc10ce7c37a87a35ad44c88b
|
|
BLAKE2b-256 |
8422a25be2fc4641d1c1de86743c8bd6c8b30641d329b451254208ea55b4991e
|