Change a relation between two mysql fields

Asked

Viewed 39 times

0

I have my event schedule (tbl_eventos), where I am going to find the id_contact field of the contacts table (tbl_contactos). To create this link, I used the following:

ALTER TABLE `tbl_eventos`
  ADD CONSTRAINT `tbl_eventos_ibfk_3` FOREIGN KEY (`id_contacto`) REFERENCES `tbl_contactos` (`id_contacto`);

What happens now is that my contact table has changed its name, which means it’s gone from tbl_contactos for tbl_contactos_cliente. How can I make this change? The code above was generated by phpmyadmin.

  • 1

    You can’t just drop and create again?

  • @Pedrolorentz, that’s not what I wanted. But if I can’t find another solution, it will have to be. Thanks anyway.

  • I’m not going to put it as an answer for now so I can instigate more people to come here and give them another choice.

  • 1

    I believe the solution of @Pedrolorentz is the most suitable as it is simple, widely used and safe.

1 answer

1


I know from the comments that it is not what I wanted exactly, but I think the best solution is to run DROP and ADD manually.

ALTER TABLE tbl_eventos DROP CONSTRAINT tbl_eventos_ibfk_3;

ALTER TABLE tbl_eventos ADD CONSTRAINT [NOME_CONSTRAINT] FOREIGN KEY (id_contacto) REFERENCES tbl_contactos_cliente (id_contacto);

(And put Fk_eventos_name contacts :] )

  • yes, I will opt for this option. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.