diff --git a/core/management/commands/sql.py b/core/management/commands/sql.py
index 1b3b1af..841c9f5 100644
a
|
b
|
class Command(AppCommand):
|
15 | 15 | parser.add_argument('--database', default=DEFAULT_DB_ALIAS, |
16 | 16 | help='Nominates a database to print the SQL for. Defaults to the ' |
17 | 17 | '"default" database.') |
| 18 | parser.add_argument('--force', default=False, action='store_true', |
| 19 | help='Skip migrations checking') |
18 | 20 | |
19 | 21 | def handle_app_config(self, app_config, **options): |
20 | 22 | if app_config.models_module is None: |
21 | 23 | return |
22 | 24 | connection = connections[options['database']] |
23 | | statements = sql_create(app_config, self.style, connection) |
| 25 | statements = sql_create(app_config, self.style, connection, |
| 26 | options['force']) |
24 | 27 | return '\n'.join(statements) |
diff --git a/core/management/commands/sqlall.py b/core/management/commands/sqlall.py
index 0a2b9c3..d216482 100644
a
|
b
|
class Command(AppCommand):
|
15 | 15 | parser.add_argument('--database', default=DEFAULT_DB_ALIAS, |
16 | 16 | help='Nominates a database to print the SQL for. Defaults to the ' |
17 | 17 | '"default" database.') |
| 18 | parser.add_argument('--force', default=False, action='store_true', |
| 19 | help='Skip migrations checking') |
18 | 20 | |
19 | 21 | def handle_app_config(self, app_config, **options): |
20 | 22 | if app_config.models_module is None: |
21 | 23 | return |
22 | 24 | connection = connections[options['database']] |
23 | | statements = sql_all(app_config, self.style, connection) |
| 25 | statements = sql_all(app_config, self.style, connection, |
| 26 | options['force']) |
24 | 27 | return '\n'.join(statements) |
diff --git a/core/management/commands/sqlindexes.py b/core/management/commands/sqlindexes.py
index ee1f395..2d62f95 100644
a
|
b
|
class Command(AppCommand):
|
15 | 15 | parser.add_argument('--database', default=DEFAULT_DB_ALIAS, |
16 | 16 | help='Nominates a database to print the SQL for. Defaults to the ' |
17 | 17 | '"default" database.') |
| 18 | parser.add_argument('--force', default=False, action='store_true', |
| 19 | help='Skip migrations checking') |
18 | 20 | |
19 | 21 | def handle_app_config(self, app_config, **options): |
20 | 22 | if app_config.models_module is None: |
21 | 23 | return |
22 | 24 | connection = connections[options['database']] |
23 | | statements = sql_indexes(app_config, self.style, connection) |
| 25 | statements = sql_indexes(app_config, self.style, connection, |
| 26 | options['force']) |
24 | 27 | return '\n'.join(statements) |
diff --git a/core/management/sql.py b/core/management/sql.py
index a189705..864b394 100644
a
|
b
|
from django.utils.deprecation import RemovedInDjango19Warning
|
13 | 13 | from django.utils.version import get_docs_version |
14 | 14 | |
15 | 15 | |
16 | | def check_for_migrations(app_config, connection): |
| 16 | def check_for_migrations(app_config, connection, force=False): |
17 | 17 | # Inner import, else tests imports it too early as it needs settings |
18 | 18 | from django.db.migrations.loader import MigrationLoader |
19 | 19 | loader = MigrationLoader(connection) |
20 | | if app_config.label in loader.migrated_apps: |
| 20 | if app_config.label in loader.migrated_apps and not force: |
21 | 21 | raise CommandError( |
22 | 22 | "App '%s' has migrations. Only the sqlmigrate and sqlflush commands " |
23 | 23 | "can be used when an app has migrations." % app_config.label |
24 | 24 | ) |
25 | 25 | |
26 | 26 | |
27 | | def sql_create(app_config, style, connection): |
| 27 | def sql_create(app_config, style, connection, force=False): |
28 | 28 | "Returns a list of the CREATE TABLE SQL statements for the given app." |
29 | 29 | |
30 | | check_for_migrations(app_config, connection) |
| 30 | check_for_migrations(app_config, connection, force) |
31 | 31 | |
32 | 32 | if connection.settings_dict['ENGINE'] == 'django.db.backends.dummy': |
33 | 33 | # This must be the "dummy" database backend, which means the user |
… |
… |
def sql_flush(style, connection, only_django=False, reset_sequences=True, allow_
|
140 | 140 | return statements |
141 | 141 | |
142 | 142 | |
143 | | def sql_custom(app_config, style, connection): |
| 143 | def sql_custom(app_config, style, connection, force=False): |
144 | 144 | "Returns a list of the custom table modifying SQL statements for the given app." |
145 | 145 | |
146 | | check_for_migrations(app_config, connection) |
| 146 | check_for_migrations(app_config, connection, force=force) |
147 | 147 | |
148 | 148 | output = [] |
149 | 149 | |
… |
… |
def sql_custom(app_config, style, connection):
|
155 | 155 | return output |
156 | 156 | |
157 | 157 | |
158 | | def sql_indexes(app_config, style, connection): |
| 158 | def sql_indexes(app_config, style, connection, force=False): |
159 | 159 | "Returns a list of the CREATE INDEX SQL statements for all models in the given app." |
160 | 160 | |
161 | | check_for_migrations(app_config, connection) |
| 161 | check_for_migrations(app_config, connection, force=force) |
162 | 162 | |
163 | 163 | output = [] |
164 | 164 | for model in router.get_migratable_models(app_config, connection.alias, include_auto_created=True): |
… |
… |
def sql_destroy_indexes(app_config, style, connection):
|
177 | 177 | return output |
178 | 178 | |
179 | 179 | |
180 | | def sql_all(app_config, style, connection): |
| 180 | def sql_all(app_config, style, connection, force=False): |
181 | 181 | |
182 | | check_for_migrations(app_config, connection) |
| 182 | check_for_migrations(app_config, connection, force=force) |
183 | 183 | |
184 | 184 | "Returns a list of CREATE TABLE SQL, initial-data inserts, and CREATE INDEX SQL for the given module." |
185 | 185 | return ( |
186 | | sql_create(app_config, style, connection) + |
187 | | sql_custom(app_config, style, connection) + |
188 | | sql_indexes(app_config, style, connection) |
| 186 | sql_create(app_config, style, connection, force=force) + |
| 187 | sql_custom(app_config, style, connection, force=force) + |
| 188 | sql_indexes(app_config, style, connection, force=force) |
189 | 189 | ) |
190 | 190 | |
191 | 191 | |