diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
index fa0feff..b417e09 100644
--- a/django/db/backends/creation.py
+++ b/django/db/backends/creation.py
@@ -285,7 +285,11 @@ class BaseDatabaseCreation(object):
         # Create the test database and connect to it. We need to autocommit
         # if the database supports it because PostgreSQL doesn't allow
         # CREATE/DROP DATABASE statements within transactions.
+        old_name = self.connection.settings_dict['NAME']
+        self.connection.settings_dict['NAME'] = None
         cursor = self.connection.cursor()
+        self.connection.settings_dict['NAME'] = old_name
+
         self._prepare_for_test_db_ddl()
         try:
             cursor.execute("CREATE DATABASE %s %s" % (qn(test_database_name), suffix))
@@ -330,7 +334,11 @@ class BaseDatabaseCreation(object):
         # ourselves. Connect to the previous database (not the test database)
         # to do so, because it's not allowed to delete a database while being
         # connected to it.
+        old_name = self.connection.settings_dict['NAME']
+        self.connection.settings_dict['NAME'] = None
         cursor = self.connection.cursor()
+        self.connection.settings_dict['NAME'] = old_name
+
         self._prepare_for_test_db_ddl()
         time.sleep(1) # To avoid "database is being accessed by other users" errors.
         cursor.execute("DROP DATABASE %s" % self.connection.ops.quote_name(test_database_name))
diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py
index f0a89e5..1dd4a84 100644
--- a/django/db/backends/postgresql_psycopg2/base.py
+++ b/django/db/backends/postgresql_psycopg2/base.py
@@ -152,8 +152,9 @@ class DatabaseWrapper(BaseDatabaseWrapper):
             if settings_dict['NAME'] == '':
                 from django.core.exceptions import ImproperlyConfigured
                 raise ImproperlyConfigured("You need to specify NAME in your Django settings file.")
+
             conn_params = {
-                'database': settings_dict['NAME'],
+                'database': settings_dict['NAME'] or 'postgres',
             }
             conn_params.update(settings_dict['OPTIONS'])
             if 'autocommit' in conn_params:
