Is there any way I can delete all the rows from database before altering the model in django?

I want to alter my model but before doing so I want to delete all the records from my database, is there any dajngo ORM query for doing that cuz I don't want to do it manually. Thanks.

I tried to alter my model but when I migrated the changes an error occured. it was a long error but the last line was this.

File "C:\\Users\\ALI SHANAWER.virtualenvs\\PiikFM-App-Backend-O_dKS6jY\\Lib\\site-packages\\MySQLdb\\", line 254, in query \_mysql.connection.query(self, query) django.db.utils.OperationalError: (3140, 'Invalid JSON text: "Invalid value." at position 0 in value for column '#sql-45_2d01.qbo_class'.') any one knows what this is?

You can simple delete db.sqlite ie, database file
then run python makemigration and then python migrate.

I hope this is what you were looking for

If you want to truncate only a single table then use {ModelName}.objects.all().delete() otherwise use can use "python flush" for truncate database.

Back to Top