Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Made 'django-admin.py init' more robust

git-svn-id: http://code.djangoproject.com/svn/django/trunk@632 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f46402bc90e85f610d8ed564b35651e8244337b3 1 parent 93010c7
Adrian Holovaty authored

Showing 1 changed file with 10 additions and 6 deletions. Show diff stats Hide diff stats

  1. 16  django/core/management.py
16  django/core/management.py
@@ -286,19 +286,23 @@ def get_admin_index(mod):
286 286
 
287 287
 def init():
288 288
     "Initializes the database with auth and core."
289  
-    from django.core import db, meta
290  
-    auth = meta.get_app('auth')
291  
-    core = meta.get_app('core')
292 289
     try:
  290
+        from django.core import db, meta
  291
+        auth = meta.get_app('auth')
  292
+        core = meta.get_app('core')
293 293
         cursor = db.db.cursor()
294 294
         for sql in get_sql_create(core) + get_sql_create(auth) + get_sql_initial_data(core) + get_sql_initial_data(auth):
295 295
             cursor.execute(sql)
296 296
         cursor.execute("INSERT INTO %s (domain, name) VALUES ('mysite.com', 'My Django site')" % core.Site._meta.db_table)
297 297
     except Exception, e:
298  
-        sys.stderr.write("Error: The database couldn't be initialized. Here's the full exception:\n%s\n" % e)
299  
-        db.db.rollback()
  298
+        sys.stderr.write("Error: The database couldn't be initialized.\n%s\n" % e)
  299
+        try:
  300
+            db.db.rollback()
  301
+        except UnboundLocalError:
  302
+            pass
300 303
         sys.exit(1)
301  
-    db.db.commit()
  304
+    else:
  305
+        db.db.commit()
302 306
 init.args = ''
303 307
 
304 308
 def install(mod):

0 notes on commit f46402b

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