manage.py custom sql fails with triggers and sqlite
|Reported by:||hambaloney@…||Owned by:||jacob|
|Severity:||Keywords:||manage.py custom sql trigger sqlite3|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Ran into an issue where using the manage.py interface to bring in custom SQL containing triggers for sqlite causes it to fail with the error:
The full error: near ";": syntax error
Dug around to find in django/core/management.py -> get_custom_sql_for_model, the sql commands are parsed by semicolons.
sqlite triggers follow the format:
CREATE TRIGGER trigger-name [ BEFORE | AFTER ] database-event ON [database-name .] table-name BEGIN trigger step; trigger step; END;
manage.py attempts to parse and run each line ending in a semicolon separately causing the error.
As a temporary fix I've modified management.py as follows, please don't hurt me, I know its ugly. Note, I'm using sqlite3.