Error 1239: Incorrect foreign key definition
Syntax error:

alter table invoice add constraint CUS_CODE
    foreign key (CUS_CODE) references customer.CUS_CODE;


Correct syntax:

alter table INVOICE add constraint CUS_CODE
    foreign key (CUS_CODE) references CUSTOMER(CUS_CODE);


customer.CUS_CODE is treated as dbname.tablename.  What is needed is tablename(columnname) or dbname.tablename(columnname)