summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/backends/postgresql')
-rw-r--r--django/db/backends/postgresql/base.py1
-rw-r--r--django/db/backends/postgresql/introspection.py2
-rw-r--r--django/db/backends/postgresql/operations.py1
-rw-r--r--django/db/backends/postgresql/schema.py6
4 files changed, 7 insertions, 3 deletions
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
index 7e34a3a177..eea8aeb135 100644
--- a/django/db/backends/postgresql/base.py
+++ b/django/db/backends/postgresql/base.py
@@ -92,6 +92,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
'PositiveIntegerField': 'integer',
'PositiveSmallIntegerField': 'smallint',
'SlugField': 'varchar(%(max_length)s)',
+ 'SmallAutoField': 'smallserial',
'SmallIntegerField': 'smallint',
'TextField': 'text',
'TimeField': 'time',
diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py
index 1c9c7e63a5..b7bf18691c 100644
--- a/django/db/backends/postgresql/introspection.py
+++ b/django/db/backends/postgresql/introspection.py
@@ -37,6 +37,8 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
return 'AutoField'
elif field_type == 'BigIntegerField':
return 'BigAutoField'
+ elif field_type == 'SmallIntegerField':
+ return 'SmallAutoField'
return field_type
def get_table_list(self, cursor):
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
index 0c497edf71..61bac5e55a 100644
--- a/django/db/backends/postgresql/operations.py
+++ b/django/db/backends/postgresql/operations.py
@@ -11,6 +11,7 @@ class DatabaseOperations(BaseDatabaseOperations):
cast_data_types = {
'AutoField': 'integer',
'BigAutoField': 'bigint',
+ 'SmallAutoField': 'smallint',
}
def unification_cast_sql(self, output_field):
diff --git a/django/db/backends/postgresql/schema.py b/django/db/backends/postgresql/schema.py
index b7f52ccf25..eb5b182680 100644
--- a/django/db/backends/postgresql/schema.py
+++ b/django/db/backends/postgresql/schema.py
@@ -69,15 +69,15 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
self.sql_alter_column_type += ' USING %(column)s::%(type)s'
# Make ALTER TYPE with SERIAL make sense.
table = strip_quotes(model._meta.db_table)
- if new_type.lower() in ("serial", "bigserial"):
+ serial_fields_map = {'bigserial': 'bigint', 'serial': 'integer', 'smallserial': 'smallint'}
+ if new_type.lower() in serial_fields_map:
column = strip_quotes(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": col_type,
+ "type": serial_fields_map[new_type.lower()],
},
[],
),