diff --git a/AUTHORS b/AUTHORS
index a905d45877..b1b4e6b977 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -65,6 +65,7 @@ answer newbie questions, and generally made Django that much better:
Robert Rock Howard
Jason Huggins
Michael Josephson
+ jpellerin@gmail.com
junzhang.jn@gmail.com
Russell Keith-Magee
Garth Kidd
diff --git a/django/core/management.py b/django/core/management.py
index a3a28af1af..8e8133f443 100644
--- a/django/core/management.py
+++ b/django/core/management.py
@@ -328,13 +328,23 @@ def get_sql_initial_data_for_model(model):
app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), 'sql'))
output = []
+ # Some backends can't execute more than one SQL statement at a time,
+ # so split into separate statements.
+ sql_expr = re.compile(
+ r"""( # each statement is...
+ (?: # one or more chunks of ...
+ (?:[^;'"]+) # not the end of a statement or start of a quote
+ | (?:'[^']+') # something in single quotes
+ | (?:"[^"]+") # something in double quotes
+ )+)""", re.VERBOSE)
+
# Find custom SQL, if it's available.
sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), settings.DATABASE_ENGINE)),
os.path.join(app_dir, "%s.sql" % opts.object_name.lower())]
for sql_file in sql_files:
if os.path.exists(sql_file):
fp = open(sql_file)
- output.append(fp.read())
+ output.extend(sql_expr.findall(fp.read()))
fp.close()
return output