diff --git a/django/contrib/postgres/operations.py b/django/contrib/postgres/operations.py index 3bb81dc3f9..2a0a8402ed 100644 --- a/django/contrib/postgres/operations.py +++ b/django/contrib/postgres/operations.py @@ -14,10 +14,10 @@ class CreateExtension(Operation): def database_forwards(self, app_label, schema_editor, from_state, to_state): if schema_editor.connection.vendor != 'postgresql': return - schema_editor.execute("CREATE EXTENSION IF NOT EXISTS %s" % self.name) + schema_editor.execute("CREATE EXTENSION IF NOT EXISTS %s" % schema_editor.quote_name(self.name)) def database_backwards(self, app_label, schema_editor, from_state, to_state): - schema_editor.execute("DROP EXTENSION %s" % self.name) + schema_editor.execute("DROP EXTENSION %s" % schema_editor.quote_name(self.name)) def describe(self): return "Creates extension %s" % self.name diff --git a/tests/postgres_tests/migrations/0001_setup_extensions.py b/tests/postgres_tests/migrations/0001_setup_extensions.py index ad5d1c716a..07d5bfc7e7 100644 --- a/tests/postgres_tests/migrations/0001_setup_extensions.py +++ b/tests/postgres_tests/migrations/0001_setup_extensions.py @@ -5,20 +5,21 @@ from django.db import migrations try: from django.contrib.postgres.operations import ( - HStoreExtension, UnaccentExtension, + CreateExtension, HStoreExtension, UnaccentExtension, ) except ImportError: from django.test import mock + CreateExtension = mock.Mock() HStoreExtension = mock.Mock() UnaccentExtension = mock.Mock() class Migration(migrations.Migration): - dependencies = [ - ] - operations = [ + # Ensure CreateExtension quotes extension names by creating one with a + # dash in its name. + CreateExtension('uuid-ossp'), HStoreExtension(), UnaccentExtension(), ]