Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed [735] so that database-agnostic SQL always gets executed, eve…

…n if database-specific SQL doesn't exist.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@737 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 998fc72c0d10afb6df3c58aa965540a4e23af431 1 parent 27b1f69
@adrianholovaty adrianholovaty authored
Showing with 10 additions and 16 deletions.
  1. +10 −16 django/core/management.py
View
26 django/core/management.py
@@ -156,29 +156,23 @@ def get_sql_reset(mod):
def get_sql_initial_data(mod):
"Returns a list of the initial INSERT SQL statements for the given module."
+ from django.core import db
output = []
app_label = mod._MODELS[0]._meta.app_label
output.append(_get_packages_insert(app_label))
app_dir = os.path.normpath(os.path.join(os.path.dirname(mod.__file__), '../sql'))
for klass in mod._MODELS:
opts = klass._meta
+
# Add custom SQL, if it's available.
- from django.core import db
-
- # Get the sql file name for the init data for the current database engine
- db_engine_sql_file_name = os.path.join(app_dir, opts.module_name + '.' + db.DATABASE_ENGINE.lower() + '.sql')
-
- # Check if the data specific file exists
- if os.path.exists(db_engine_sql_file_name):
- sql_file_name = db_engine_sql_file_name
- # if the database specific file doesn't exist, use the database agnostic version
- else:
- sql_file_name = os.path.join(app_dir, opts.module_name + '.sql')
+ sql_files = [os.path.join(app_dir, opts.module_name + '.' + db.DATABASE_ENGINE + '.sql'),
+ os.path.join(app_dir, opts.module_name + '.sql')]
+ for sql_file in sql_files:
+ if os.path.exists(sql_file):
+ fp = open(sql_file)
+ output.append(fp.read())
+ fp.close()
- if os.path.exists(sql_file_name):
- fp = open(sql_file_name, 'r')
- output.append(fp.read())
- fp.close()
# Content types.
output.append(_get_contenttype_insert(opts))
# Permissions.
@@ -664,4 +658,4 @@ def createcachetable(tablename):
for statement in index_output:
curs.execute(statement)
db.db.commit()
-createcachetable.args = "[tablename]"
+createcachetable.args = "[tablename]"
Please sign in to comment.
Something went wrong with that request. Please try again.