Jump to content

phpmyadmin


witchy478

Recommended Posts

Hi

 

I don't know if this is in the right place but I hope you can help.

 

I would like to know how to make foreign keys. I have looked on the internet but it's not making any sense to me. Some say that you can't make foreign keys and then others give you a way to make foreign keys but I don't understand them.

 

Can someone please tell me in a simple way how to do foreign keys.

 

I'm using phpmyadmin 3.4.10.1

 

Thank you

Link to comment
https://forums.phpfreaks.com/topic/263293-phpmyadmin/
Share on other sites

Only the InnoDB supports "Real" Foreign Keys:

http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html

 

But you can have Foreign Keys in any other engine, but they won't be constant. With InnoDB, if you have a Primary Key and 10 tables that have a Foreign Key that points to the parent tables Primary Key, you can then update the primary key and all your foreign keys update along with it. In any other table you would have to update all the foreign keys manually.

 

That is as much as I have read/heard about Foreign Keys.

Link to comment
https://forums.phpfreaks.com/topic/263293-phpmyadmin/#findComment-1349393
Share on other sites

Thanks for replying I tried to do the foreign keys and I get this error:

 

ERROR: Cannot add or update a child row: a foreign key constraint fails (`test`.`friend_emails`, CONSTRAINT `friend_emails_ibfk_3` FOREIGN KEY (`email_id`) REFERENCES `emails` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)

Link to comment
https://forums.phpfreaks.com/topic/263293-phpmyadmin/#findComment-1349752
Share on other sites

  • 2 weeks later...

I get an error saying: 

 

ERROR: Cannot add or update a child row: a foreign key constraint fails ('test"."friend_emails', CONSTRAINT 'friend_emails_ibfk_1' FOREIGN KEY('email_id') REFERENCES 'emails' ('email_id) ON UPDATE CASCADE)

 

In my emails table I have email_id, name, email, password.

My email_id is a primary key, it's type int(11), attributes unsigned.

 

In my friend_emails table I have id, email_id, friend1, friend2, friend3.

My id is the primary key, attributes unsigned.

My email_id is index, attributes unsigned.

Link to comment
https://forums.phpfreaks.com/topic/263293-phpmyadmin/#findComment-1354806
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.