You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sqlsequencereset.py 872B

1234567891011121314151617181920212223
  1. from django.core.management.base import AppCommand
  2. from django.db import DEFAULT_DB_ALIAS, connections
  3. class Command(AppCommand):
  4. help = 'Prints the SQL statements for resetting sequences for the given app name(s).'
  5. output_transaction = True
  6. def add_arguments(self, parser):
  7. super().add_arguments(parser)
  8. parser.add_argument(
  9. '--database', default=DEFAULT_DB_ALIAS,
  10. help='Nominates a database to print the SQL for. Defaults to the "default" database.',
  11. )
  12. def handle_app_config(self, app_config, **options):
  13. if app_config.models_module is None:
  14. return
  15. connection = connections[options['database']]
  16. models = app_config.get_models(include_auto_created=True)
  17. statements = connection.ops.sequence_reset_sql(self.style, models)
  18. return '\n'.join(statements)