def sql_create(app_config, style, connection):
"Returns a list of the CREATE TABLE SQL statements for the given app."
if connection.settings_dict['ENGINE'] == 'django.db.backends.dummy':
# This must be the "dummy" database backend, which means the user
# hasn't set ENGINE for the database.
raise CommandError(
"Django doesn't know which syntax to use for your SQL statements,"
"\nbecause you haven't properly specified the ENGINE setting for "
"the database.\n"
"see: https://docs.djangoproject.com/en/%s/ref/settings/"
"#databases" % get_docs_version()
)
# Get installed models, so we generate REFERENCES right.
# We trim models from the current app so that the sqlreset command does not
# generate invalid SQL (leaving models out of known_models is harmless, so
# we can be conservative).
final_output = []
output = []
for model in router.get_migratable_models(
app_config, connection.alias, include_auto_created=True):
with connection.schema_editor() as editor:
output += sql_create_model(editor, model)
final_output.extend(editor.deferred_sql)
editor.deferred_sql = []
return output + final_output
评论列表
文章目录