At opencart2.0, I want to create a ocmod extension, In install.sql, I need to modify the database field. When I modify the database field, I need to decide if the field exists. Ive tried multiple variations of this, but none of them seem to work. Any ideas? Thanks in advance.

this is my install.sql,but is error

DROP PROCEDURE IF EXISTS add_col_need_credit; 
DELIMITER $$ CREATE PROCEDURE add_col_need_credit() BEGIN IF NOT EXISTS(SELECT column_name FROM information_schema.columns WHERE table_name='oc_customer_group_description' AND column_name='need_credit' ) THEN ALTER TABLE  `oc_customer_group_description`  ADD  `need_credit` numeric(10,4) NOT NULL default 0; END IF;END$$ DELIMITER ; 
CALL add_col_need_credit();
2

There are 2 best solutions below

0
On BEST ANSWER

this is not error,you can in mysql console use it

DROP PROCEDURE IF EXISTS add_col_need_credit; 
DELIMITER $$ CREATE PROCEDURE add_col_need_credit() BEGIN IF NOT EXISTS(SELECT column_name FROM information_schema.columns WHERE table_name='oc_customer_group_description' AND column_name='need_credit' ) THEN ALTER TABLE  `oc_customer_group_description`  ADD  `need_credit` numeric(10,4) NOT NULL default 0; END IF;END$$ DELIMITER ; 
CALL add_col_need_credit();
0
On
DROP PROCEDURE IF EXISTS add_col_need_credit; 
DELIMITER $$ CREATE PROCEDURE add_col_need_credit() BEGIN IF NOT EXISTS(SELECT column_name FROM information_schema.columns WHERE table_name='oc_customer_group_description' AND column_name='need_credit' ) THEN ALTER TABLE  `oc_customer_group_description`  ADD  `need_credit` numeric(10,4) NOT NULL default 0; END IF;END$$ DELIMITER ; 
CALL add_col_need_credit();