mirror of
https://github.com/django/django.git
synced 2024-12-26 19:16:11 +00:00
Made 'django-admin.py init' more robust
git-svn-id: http://code.djangoproject.com/svn/django/trunk@632 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
93010c75f2
commit
f46402bc90
@ -286,18 +286,22 @@ get_admin_index.args = APP_ARGS
|
|||||||
|
|
||||||
def init():
|
def init():
|
||||||
"Initializes the database with auth and core."
|
"Initializes the database with auth and core."
|
||||||
|
try:
|
||||||
from django.core import db, meta
|
from django.core import db, meta
|
||||||
auth = meta.get_app('auth')
|
auth = meta.get_app('auth')
|
||||||
core = meta.get_app('core')
|
core = meta.get_app('core')
|
||||||
try:
|
|
||||||
cursor = db.db.cursor()
|
cursor = db.db.cursor()
|
||||||
for sql in get_sql_create(core) + get_sql_create(auth) + get_sql_initial_data(core) + get_sql_initial_data(auth):
|
for sql in get_sql_create(core) + get_sql_create(auth) + get_sql_initial_data(core) + get_sql_initial_data(auth):
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
cursor.execute("INSERT INTO %s (domain, name) VALUES ('mysite.com', 'My Django site')" % core.Site._meta.db_table)
|
cursor.execute("INSERT INTO %s (domain, name) VALUES ('mysite.com', 'My Django site')" % core.Site._meta.db_table)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
sys.stderr.write("Error: The database couldn't be initialized. Here's the full exception:\n%s\n" % e)
|
sys.stderr.write("Error: The database couldn't be initialized.\n%s\n" % e)
|
||||||
|
try:
|
||||||
db.db.rollback()
|
db.db.rollback()
|
||||||
|
except UnboundLocalError:
|
||||||
|
pass
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
else:
|
||||||
db.db.commit()
|
db.db.commit()
|
||||||
init.args = ''
|
init.args = ''
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user