mirror of
https://github.com/django/django.git
synced 2025-10-26 23:26:08 +00:00
Fixed #14286 -- Added models.BigAutoField.
This commit is contained in:
committed by
Tim Graham
parent
a1d0c60fa0
commit
2a7ce34600
@@ -15,7 +15,8 @@ from django.contrib.gis.gdal import (
|
||||
SpatialReference,
|
||||
)
|
||||
from django.contrib.gis.gdal.field import (
|
||||
OFTDate, OFTDateTime, OFTInteger, OFTReal, OFTString, OFTTime,
|
||||
OFTDate, OFTDateTime, OFTInteger, OFTInteger64, OFTReal, OFTString,
|
||||
OFTTime,
|
||||
)
|
||||
from django.core.exceptions import FieldDoesNotExist, ObjectDoesNotExist
|
||||
from django.db import connections, models, router, transaction
|
||||
@@ -60,6 +61,7 @@ class LayerMapping(object):
|
||||
# counterparts.
|
||||
FIELD_TYPES = {
|
||||
models.AutoField: OFTInteger,
|
||||
models.BigAutoField: OFTInteger64,
|
||||
models.IntegerField: (OFTInteger, OFTReal, OFTString),
|
||||
models.FloatField: (OFTInteger, OFTReal),
|
||||
models.DateField: OFTDate,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)',
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)',
|
||||
|
||||
@@ -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)',
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
[],
|
||||
),
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user