diff --git a/django/core/management.py b/django/core/management.py index 684020f9d1..bf48b2bd89 100644 --- a/django/core/management.py +++ b/django/core/management.py @@ -333,14 +333,7 @@ def get_sql_initial_data_for_model(model): # 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 ... - [^\r\n;] # starts with something other than a line ending or ';' - (?: # then has 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) + statements = re.compile(r";[ \t]*$", re.M) # Find custom SQL, if it's available. sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), settings.DATABASE_ENGINE)), @@ -348,7 +341,9 @@ def get_sql_initial_data_for_model(model): for sql_file in sql_files: if os.path.exists(sql_file): fp = open(sql_file) - output.extend(sql_expr.findall(fp.read())) + for statement in statements.split(fp.read()): + if statement.strip(): + output.append(statement + ";") fp.close() return output diff --git a/tests/regressiontests/initial_sql_regress/sql/simple.sql b/tests/regressiontests/initial_sql_regress/sql/simple.sql index ac60c0c3d6..d9cd9893b5 100644 --- a/tests/regressiontests/initial_sql_regress/sql/simple.sql +++ b/tests/regressiontests/initial_sql_regress/sql/simple.sql @@ -2,4 +2,5 @@ INSERT INTO initial_sql_regress_simple (name) VALUES ('John'); INSERT INTO initial_sql_regress_simple (name) VALUES ('Paul'); INSERT INTO initial_sql_regress_simple (name) VALUES ('Ringo'); INSERT INTO initial_sql_regress_simple (name) VALUES ('George'); +INSERT INTO initial_sql_regress_simple (name) VALUES ('Miles O''Brien');