mirror of
https://github.com/nprasad2077/nbaStats.git
synced 2026-11-16 14:53:48 +00:00
script to reset SQL table at id 1 added
This commit is contained in:
1 parent
857faf17d4
commit
50af7d9fc8
1 file changed
+17
@@ -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'))
|
||||||
Reference in new issue
Block a user