UPDATE IGNORE vn.invoiceIn SET currencyFk = 1 WHERE NOT currencyFk; ALTER TABLE vn.invoiceIn ADD CONSTRAINT invoiceIn_FK FOREIGN KEY (currencyFk) REFERENCES vn.currency(id) ON DELETE RESTRICT ON UPDATE CASCADE;