diff --git a/django/core/management/sql.py b/django/core/management/sql.py
index 8bfdadb..8512cca 100644
a
|
b
|
def custom_sql_for_model(model, style, connection):
|
168 | 168 | os.path.join(app_dir, "%s.sql" % opts.object_name.lower())] |
169 | 169 | for sql_file in sql_files: |
170 | 170 | if os.path.exists(sql_file): |
171 | | fp = open(sql_file, 'rbU') |
172 | | for statement in statements.split(fp.read().decode(settings.FILE_CHARSET)): |
| 171 | # First try opening the file Python3 style. |
| 172 | # The encoding parameter is only available in Python3. |
| 173 | # If that fails open it in the traditional 2.x style and decode the |
| 174 | # result. |
| 175 | try: |
| 176 | fp = open(sql_file, 'r', encoding=settings.FILE_CHARSET) |
| 177 | sql_data = fp.read() |
| 178 | except TypeError: |
| 179 | fp = open(sql_file, 'rU') |
| 180 | sql_data = fp.read().decode(settings.FILE_CHARSET) |
| 181 | |
| 182 | for statement in statements.split(sql_data): |
173 | 183 | # Remove any comments from the file |
174 | 184 | statement = re.sub(ur"--.*([\n\Z]|$)", "", statement) |
175 | 185 | if statement.strip(): |