[Django] Perform Truncate Table (delete all data in the table)

When changing models in Django, there are cases where you want to delete all the data inside.

Do it with a python script

python manage.py shell

After logging in to the shell with


from * import models.table

table.objects.all().delete()

Do with SQL statement


python manage.py dbshell

After logging in to dbshell with, issue `` `TRUNCATE TABLE```

reference

Recommended Posts

[Django] Perform Truncate Table (delete all data in the table)
Rename table columns in Django3
Output table structure in Django
Switch the language displayed in Django 1.9
Check the data summary in CASTable
The meaning of ".object" in Django
Get the query string (query string) in Django
Added a function to register desired shifts in the Django shift table
Get the client's IP address in Django
Django ~ Let's display it in the browser ~
How to delete expired sessions in Django
Associate the table set in python models.py
I saved the scraped data in CSV!
Django shift table shift data creation function completed
Try hitting the Spotify API in Django.
[Python] Combine all the elements in the array
I'm addicted to the difference in how Flask and Django receive JSON data
The _authenticate_with_backend function was obsolete in django auth.autenticate
Delete vertices that meet the conditions in networkx
Delete data in a pattern with Redis Cluster
[Automation] Extract the table in PDF with Python
Delete all pyc files under the specified directory
The story of reading HSPICE data in Python
Specify the view URL in your Django template
The story of viewing media files in Django
[Django] css in the project cannot be read
In bash, "Delete the file if it exists".
Display the Django shift table! Supports 20-day closing