From 50af7d9fc83e1bef69b0a4cf1a163e430e14ce1e Mon Sep 17 00:00:00 2001 From: nprasad2077 <114438461+nprasad2077@users.noreply.github.com> Date: Thu, 20 Apr 2023 17:44:47 -0500 Subject: [PATCH] script to reset SQL table at id 1 added --- .../commands/delete_player_data_and_reset_id.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 nba_data/management/commands/delete_player_data_and_reset_id.py diff --git a/nba_data/management/commands/delete_player_data_and_reset_id.py b/nba_data/management/commands/delete_player_data_and_reset_id.py new file mode 100644 index 0000000..10b2bbf --- /dev/null +++ b/nba_data/management/commands/delete_player_data_and_reset_id.py @@ -0,0 +1,17 @@ +from django.core.management.base import BaseCommand +from nba_data.models import PlayerData +from django.db import connection + +class Command(BaseCommand): + # Provides a description for use with the custom django management command (python manage.py help). + help = 'Delete all player data and reset primary key sequence in DB' + + def handle(self, *args, **options): + # Delete all player data + PlayerData.objects.all().delete() + + # Reset the PK sequence + with connection.cursor() as cursor: + cursor.execute('ALTER SEQUENCE nba_data_playerdata_id_seq RESTART WITH 1;') + + self.stdout.write(self.style.SUCCESS('Successfully deleted all players in DB')) \ No newline at end of file