summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorAlexander Sosnovskiy <alecs.box@gmail.com>2015-07-02 11:43:15 +0300
committerTim Graham <timograham@gmail.com>2015-12-25 20:01:31 -0500
commit2a7ce34600d0f879e93c9a5e02215948ed3bb6ac (patch)
treed1a4770772b452513e1d64c090dc15ae287afe70 /django/db
parenta1d0c60fa05cbad2e5a25ec37e0afaf1b84c9302 (diff)
Fixed #14286 -- Added models.BigAutoField.
Diffstat (limited to 'django/db')
-rw-r--r--django/db/backends/base/schema.py2
-rw-r--r--django/db/backends/mysql/base.py1
-rw-r--r--django/db/backends/mysql/introspection.py8
-rw-r--r--django/db/backends/oracle/base.py1
-rw-r--r--django/db/backends/postgresql/base.py1
-rw-r--r--django/db/backends/postgresql/introspection.py7
-rw-r--r--django/db/backends/postgresql/schema.py5
-rw-r--r--django/db/backends/sqlite3/base.py2
-rw-r--r--django/db/models/fields/__init__.py26
9 files changed, 38 insertions, 15 deletions
diff --git a/django/db/backends/base/schema.py b/django/db/backends/base/schema.py
index 2aa486c91e..191478a6a3 100644
--- a/django/db/backends/base/schema.py
+++ b/django/db/backends/base/schema.py
@@ -261,7 +261,7 @@ class BaseDatabaseSchemaEditor(object):
definition,
))
# Autoincrement SQL (for backends with post table definition variant)
- if field.get_internal_type() == "AutoField":
+ if field.get_internal_type() in ("AutoField", "BigAutoField"):
autoinc_sql = self.connection.ops.autoinc_sql(model._meta.db_table, field.column)
if autoinc_sql:
self.deferred_sql.extend(autoinc_sql)
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index 6fbf15e42e..f674232ab3 100644
--- a/django/db/backends/mysql/base.py
+++ b/django/db/backends/mysql/base.py
@@ -153,6 +153,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
# If a column type is set to None, it won't be included in the output.
_data_types = {
'AutoField': 'integer AUTO_INCREMENT',
+ 'BigAutoField': 'bigint AUTO_INCREMENT',
'BinaryField': 'longblob',
'BooleanField': 'bool',
'CharField': 'varchar(%(max_length)s)',
diff --git a/django/db/backends/mysql/introspection.py b/django/db/backends/mysql/introspection.py
index 0a22357cf9..3d0f6f3689 100644
--- a/django/db/backends/mysql/introspection.py
+++ b/django/db/backends/mysql/introspection.py
@@ -38,8 +38,12 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
def get_field_type(self, data_type, description):
field_type = super(DatabaseIntrospection, self).get_field_type(data_type, description)
- if field_type == 'IntegerField' and 'auto_increment' in description.extra:
- return 'AutoField'
+ if 'auto_increment' in description.extra:
+ if field_type == 'IntegerField':
+ return 'AutoField'
+ elif field_type == 'BigIntegerField':
+ return 'BigAutoField'
+
return field_type
def get_table_list(self, cursor):
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index d286ad0fff..ef93300737 100644
--- a/django/db/backends/oracle/base.py
+++ b/django/db/backends/oracle/base.py
@@ -92,6 +92,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
# output (the "qn_" prefix is stripped before the lookup is performed.
data_types = {
'AutoField': 'NUMBER(11)',
+ 'BigAutoField': 'NUMBER(19)',
'BinaryField': 'BLOB',
'BooleanField': 'NUMBER(1)',
'CharField': 'NVARCHAR2(%(max_length)s)',
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
index 383601e477..7822c66327 100644
--- a/django/db/backends/postgresql/base.py
+++ b/django/db/backends/postgresql/base.py
@@ -72,6 +72,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
# If a column type is set to None, it won't be included in the output.
data_types = {
'AutoField': 'serial',
+ 'BigAutoField': 'bigserial',
'BinaryField': 'bytea',
'BooleanField': 'boolean',
'CharField': 'varchar(%(max_length)s)',
diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py
index 9b3e9074b2..90b7090464 100644
--- a/django/db/backends/postgresql/introspection.py
+++ b/django/db/backends/postgresql/introspection.py
@@ -46,8 +46,11 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
def get_field_type(self, data_type, description):
field_type = super(DatabaseIntrospection, self).get_field_type(data_type, description)
- if field_type == 'IntegerField' and description.default and 'nextval' in description.default:
- return 'AutoField'
+ if description.default and 'nextval' in description.default:
+ if field_type == 'IntegerField':
+ return 'AutoField'
+ elif field_type == 'BigIntegerField':
+ return 'BigAutoField'
return field_type
def get_table_list(self, cursor):
diff --git a/django/db/backends/postgresql/schema.py b/django/db/backends/postgresql/schema.py
index cc31aadf0a..42d01f002d 100644
--- a/django/db/backends/postgresql/schema.py
+++ b/django/db/backends/postgresql/schema.py
@@ -54,14 +54,15 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
"""
Makes ALTER TYPE with SERIAL make sense.
"""
- if new_type.lower() == "serial":
+ if new_type.lower() in ("serial", "bigserial"):
column = new_field.column
sequence_name = "%s_%s_seq" % (table, column)
+ col_type = "integer" if new_type.lower() == "serial" else "bigint"
return (
(
self.sql_alter_column_type % {
"column": self.quote_name(column),
- "type": "integer",
+ "type": col_type,
},
[],
),
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index da9a21cbe9..55b97e8bd2 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -93,6 +93,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
# schema inspection is more useful.
data_types = {
'AutoField': 'integer',
+ 'BigAutoField': 'integer',
'BinaryField': 'BLOB',
'BooleanField': 'bool',
'CharField': 'varchar(%(max_length)s)',
@@ -120,6 +121,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
}
data_types_suffix = {
'AutoField': 'AUTOINCREMENT',
+ 'BigAutoField': 'AUTOINCREMENT',
}
# SQLite requires LIKE statements to include an ESCAPE clause if the value
# being escaped has a percent or underscore in it.
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index d16c58d29b..7a2dfdbd7d 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -42,14 +42,14 @@ from django.utils.translation import ugettext_lazy as _
# Avoid "TypeError: Item in ``from list'' not a string" -- unicode_literals
# makes these strings unicode
__all__ = [str(x) for x in (
- 'AutoField', 'BLANK_CHOICE_DASH', 'BigIntegerField', 'BinaryField',
- 'BooleanField', 'CharField', 'CommaSeparatedIntegerField', 'DateField',
- 'DateTimeField', 'DecimalField', 'DurationField', 'EmailField', 'Empty',
- 'Field', 'FieldDoesNotExist', 'FilePathField', 'FloatField',
- 'GenericIPAddressField', 'IPAddressField', 'IntegerField', 'NOT_PROVIDED',
- 'NullBooleanField', 'PositiveIntegerField', 'PositiveSmallIntegerField',
- 'SlugField', 'SmallIntegerField', 'TextField', 'TimeField', 'URLField',
- 'UUIDField',
+ 'AutoField', 'BLANK_CHOICE_DASH', 'BigAutoField', 'BigIntegerField',
+ 'BinaryField', 'BooleanField', 'CharField', 'CommaSeparatedIntegerField',
+ 'DateField', 'DateTimeField', 'DecimalField', 'DurationField',
+ 'EmailField', 'Empty', 'Field', 'FieldDoesNotExist', 'FilePathField',
+ 'FloatField', 'GenericIPAddressField', 'IPAddressField', 'IntegerField',
+ 'NOT_PROVIDED', 'NullBooleanField', 'PositiveIntegerField',
+ 'PositiveSmallIntegerField', 'SlugField', 'SmallIntegerField', 'TextField',
+ 'TimeField', 'URLField', 'UUIDField',
)]
@@ -997,6 +997,16 @@ class AutoField(Field):
return None
+class BigAutoField(AutoField):
+ description = _("Big (8 byte) integer")
+
+ def get_internal_type(self):
+ return "BigAutoField"
+
+ def rel_db_type(self, connection):
+ return BigIntegerField().db_type(connection=connection)
+
+
class BooleanField(Field):
empty_strings_allowed = False
default_error_messages = {