I have a table and it have a ForeignKeyField referencing another table. ON DELETE functionality is supported by initializing ForeignKeyField with an on_delete argument. Though it's not very clear what values on_delete can take, the documentation gives an example, e.g. 'CASCADE'. This being said, on_delete='CASCADE' seems to have no effect, as attempting to delete a row from one of the parent tables throws an error.
this is an example that does NOT work:
import peewee
db = peewee.SqliteDatabase("base.db")
class BaseModel(peewee.Model):
class Meta:
database = db
class Grades(BaseModel):
year = peewee.IntegerField()
division = peewee.CharField(max_length=1)
class Student(BaseModel):
dni = peewee.IntegerField()
name = peewee.CharField(max_length=40)
surname = peewee.CharField(max_length=40)
gender = peewee.CharField(max_length=1)
grade = peewee.ForeignKeyField(Grades, on_delete="CASCADE")
what I expect is that when deleting a grade, the students of this grade are deleted