Ticket #16969: test_db_creation.diff

File test_db_creation.diff, 2.2 KB (added by Andreas Pelme, 13 years ago)
  • django/db/backends/creation.py

    diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
    index fa0feff..b417e09 100644
    a b class BaseDatabaseCreation(object):  
    285285        # Create the test database and connect to it. We need to autocommit
    286286        # if the database supports it because PostgreSQL doesn't allow
    287287        # CREATE/DROP DATABASE statements within transactions.
     288        old_name = self.connection.settings_dict['NAME']
     289        self.connection.settings_dict['NAME'] = None
    288290        cursor = self.connection.cursor()
     291        self.connection.settings_dict['NAME'] = old_name
     292
    289293        self._prepare_for_test_db_ddl()
    290294        try:
    291295            cursor.execute("CREATE DATABASE %s %s" % (qn(test_database_name), suffix))
    class BaseDatabaseCreation(object):  
    330334        # ourselves. Connect to the previous database (not the test database)
    331335        # to do so, because it's not allowed to delete a database while being
    332336        # connected to it.
     337        old_name = self.connection.settings_dict['NAME']
     338        self.connection.settings_dict['NAME'] = None
    333339        cursor = self.connection.cursor()
     340        self.connection.settings_dict['NAME'] = old_name
     341
    334342        self._prepare_for_test_db_ddl()
    335343        time.sleep(1) # To avoid "database is being accessed by other users" errors.
    336344        cursor.execute("DROP DATABASE %s" % self.connection.ops.quote_name(test_database_name))
  • django/db/backends/postgresql_psycopg2/base.py

    diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py
    index f0a89e5..1dd4a84 100644
    a b class DatabaseWrapper(BaseDatabaseWrapper):  
    152152            if settings_dict['NAME'] == '':
    153153                from django.core.exceptions import ImproperlyConfigured
    154154                raise ImproperlyConfigured("You need to specify NAME in your Django settings file.")
     155
    155156            conn_params = {
    156                 'database': settings_dict['NAME'],
     157                'database': settings_dict['NAME'] or 'postgres',
    157158            }
    158159            conn_params.update(settings_dict['OPTIONS'])
    159160            if 'autocommit' in conn_params:
Back to Top