'Python 3.x Tortoise-orm Delete all values inside the database SQLite
So I've recently starting learning about tortoise-orm. But I have a question: How would I get all the data inside the SQLite database and delete all of them?
Ex Model:
from tortoise.models import Model
from tortoise import fields
class Counter(Model):
count = fields.IntField()
def __str__(self):
return self.name
Solution 1:[1]
you can :
- get all the data by querying
Counter.all()
. Awaiting this will give you a python list ofCounter
objects. - delete the entire database by doing,
await Tortoise._drop_database()
BEWARE OF DROPPING THE DATABSE, YOU WILL LOSE ALL YOU DATA
Tries to drop all databases provided in config passed to .init() method. Normally should be used only for testing purposes.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kanishk |