Django migration sql for conditional triggers

前端 未结 2 1023
离开以前
离开以前 2021-01-29 04:53

I want to create a trigger that only inserts into table when the condition is met. I\'ve tried using various combinations of IF/BEGIN/END and WHERE, but Django returns me an SQ

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-29 05:13

    Another easy way to do this.

    You should add any symbols between ; delimiters for the appropriate converting MySQL syntax to the raw SQL.

    CREATE TRIGGER trigger_name BEFORE INSERT ON table
    FOR EACH ROW
    BEGIN
    IF NEW.number <> 'anynumber' AND NEW.number <> 'anynumber'
      THEN
        SET NEW.number = 'anynumber'; --
    END IF; --
    END
    

    This example works due to the dash symbols.

提交回复
热议问题