django-concurrency
django-concurrency copied to clipboard
Trigger already exists
During migrations (after concurrency has been added I'm running into this:
CREATE OR REPLACE FUNCTION func_concurrency_games_gamecontext_version()
RETURNS TRIGGER as
'
BEGIN
NEW.version = OLD.version +1;
RETURN NEW;
END;
' language 'plpgsql';
CREATE TRIGGER concurrency_games_gamecontext_version BEFORE UPDATE
ON games_gamecontext FOR EACH ROW
EXECUTE PROCEDURE func_concurrency_games_gamecontext_version();
trigger "concurrency_games_gamecontext_version" for relation "games_gamecontext" already exists
I think there is something missing right before CREATE TRIGGER and that would be
DROP TRIGGER IF EXISTS concurrency_games_gamecontext_version
Unfortunately there is no CREATE OR REPLACE TRIGGER so I think if the code is going to create it, it should drop it first IF EXISTS.
I have no CONCURRENCY settings in my settings.py file
Not sure why there is a drop_clause unless it is for when your remove concurrency from the project.
class PostgreSQL(TriggerFactory):
drop_clause = r"""DROP TRIGGER IF EXISTS {trigger_name} ON {opts.db_table};"""
update_clause = r"""CREATE OR REPLACE FUNCTION func_{trigger_name}()
RETURNS TRIGGER as
'
BEGIN
NEW.{field.column} = OLD.{field.column} +1;
RETURN NEW;
END;
' language 'plpgsql';
DROP TRIGGER IF EXISTS {trigger_name} ON {opts.db_table};
CREATE TRIGGER {trigger_name} BEFORE UPDATE
ON {opts.db_table} FOR EACH ROW
EXECUTE PROCEDURE func_{trigger_name}();
"""
Fixes the problem for me in triggers.py
Seems you added triggers manually or using the management command. can you remove them with ./manage.py triggers... ?
closing due to missing feedback