-
I have this route: @router.delete("/{team_id}")
async def delete_team(team_id: int) -> None:
team = await Team.objects.get(pk=team_id)
await team.delete() Other objects in the database have foreign keys pointing to teams. {
"error": "integrity error",
"details": "FOREIGN KEY constraint failed"
} The response is coming from this handler: @app.exception_handler(sqlite3.IntegrityError)
async def integrity_error_handler(request: Request, exc: sqlite3.IntegrityError) -> JSONResponse:
return JSONResponse(
status_code=400,
content={"error": "integrity error", "details": str(exc)},
) I searched for "cascade" in the docs but couldn't find anything. Was I supposed to set |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Ah, I see, it's here: https://collerek.github.io/ormar/api/fields/foreign-key/#populate_fk_params_based_on_to_model |
Beta Was this translation helpful? Give feedback.
-
Hmm maybe I missed that in the docs, you can pass source: Optional[DataSource] = ormar.ForeignKey(DataSource, ondelete="CASCADE") If you want to cascades the delete then use.. |
Beta Was this translation helpful? Give feedback.
Hmm maybe I missed that in the docs, you can pass
ondelete
andonupdate
inForeignKey
like:If you want to cascades the delete then use..
CASCADE
:)Those options are passed to sqlalchemy so you can check available options there.