Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10364 -- Correctly identify test spatial database creation err…

…ors to the user.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10603 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit bfe36750b157d744c83a6aaea1bf2cb95afdf65d 1 parent be11bd4
Justin Bronn authored
21  django/contrib/gis/db/backend/postgis/creation.py
@@ -46,16 +46,19 @@ def _create_with_cursor(db_name, verbosity=1, autoclobber=False):
46 46
         # Trying to create the database first.
47 47
         cursor.execute(create_sql)
48 48
     except Exception, e:
49  
-        # Drop and recreate, if necessary.
50  
-        if not autoclobber:
51  
-            confirm = raw_input("\nIt appears the database, %s, already exists. Type 'yes' to delete it, or 'no' to cancel: " % db_name)
52  
-        if autoclobber or confirm == 'yes':
53  
-            if verbosity >= 1: print 'Destroying old spatial database...'
54  
-            drop_db(db_name)
55  
-            if verbosity >= 1: print 'Creating new spatial database...'
56  
-            cursor.execute(create_sql)
  49
+        if 'already exists' in e.pgerror.lower():
  50
+            # Database already exists, drop and recreate if user agrees.
  51
+            if not autoclobber:
  52
+                confirm = raw_input("\nIt appears the database, %s, already exists. Type 'yes' to delete it, or 'no' to cancel: " % db_name)
  53
+            if autoclobber or confirm == 'yes':
  54
+                if verbosity >= 1: print 'Destroying old spatial database...'
  55
+                drop_db(db_name)
  56
+                if verbosity >= 1: print 'Creating new spatial database...'
  57
+                cursor.execute(create_sql)
  58
+            else:
  59
+                raise Exception('Spatial database creation canceled.')
57 60
         else:
58  
-            raise Exception('Spatial Database Creation canceled.')
  61
+            raise Exception('Spatial database creation failed: "%s"' % e.pgerror.strip())
59 62
 
60 63
 created_regex = re.compile(r'^createdb: database creation failed: ERROR:  database ".+" already exists')
61 64
 def _create_with_shell(db_name, verbosity=1, autoclobber=False):

0 notes on commit bfe3675

Please sign in to comment.
Something went wrong with that request. Please try again.