From d7b2aa24f75434c2ce50100cfef3586071e0747a Mon Sep 17 00:00:00 2001 From: Дилян Палаузов Date: Wed, 3 Jan 2018 18:52:12 -0500 Subject: Fixed #28982 -- Simplified code with and/or. --- django/db/backends/postgresql/creation.py | 4 +--- django/db/backends/postgresql/operations.py | 8 +++----- 2 files changed, 4 insertions(+), 8 deletions(-) (limited to 'django/db/backends/postgresql') diff --git a/django/db/backends/postgresql/creation.py b/django/db/backends/postgresql/creation.py index a93bdbb4a1..0169fc5c1f 100644 --- a/django/db/backends/postgresql/creation.py +++ b/django/db/backends/postgresql/creation.py @@ -16,9 +16,7 @@ class DatabaseCreation(BaseDatabaseCreation): suffix += " ENCODING '{}'".format(encoding) if template: suffix += " TEMPLATE {}".format(self._quote_name(template)) - if suffix: - suffix = "WITH" + suffix - return suffix + return suffix and "WITH" + suffix def sql_table_creation_suffix(self): test_settings = self.connection.settings_dict['TEST'] diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py index 06a46f4303..3b71cd4f2c 100644 --- a/django/db/backends/postgresql/operations.py +++ b/django/db/backends/postgresql/operations.py @@ -131,11 +131,9 @@ class DatabaseOperations(BaseDatabaseOperations): sql = [] for sequence_info in sequences: table_name = sequence_info['table'] - column_name = sequence_info['column'] - if not column_name: - # This will be the case if it's an m2m using an autogenerated - # intermediate table (see BaseDatabaseIntrospection.sequence_list) - column_name = 'id' + # 'id' will be the case if it's an m2m using an autogenerated + # intermediate table (see BaseDatabaseIntrospection.sequence_list). + column_name = sequence_info['column'] or 'id' sql.append("%s setval(pg_get_serial_sequence('%s','%s'), 1, false);" % ( style.SQL_KEYWORD('SELECT'), style.SQL_TABLE(self.quote_name(table_name)), -- cgit v1.3