DevStarlight
DevStarlight

Reputation: 804

foreign keys mysql and phpmyadmin

I'm developing a website with php + mysql(phpMyAdmin).

I got 2 tables: USERS and FOLLOWERS like in the link i've pasted here below:

enter image description here

These tables are created with a sql script that I paste here bellow:

DROP TABLE IF EXISTS `FOLLOWERS`;
CREATE TABLE IF NOT EXISTS `FOLLOWERS` (
  `Follower1_Id` int(10) unsigned NOT NULL,
  `Follower2_Id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`Follower1_Id`, `Follower2_Id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

(I just paste the table "FOLLOWERS" due to in that table is where is the problem).

Due to i don't know why phpMyAdmin doesn't allow to insert foreign keys, the problem comes when i try to insert a follower based on the USERS table. For any reason i can insert the user nº5 when i only have 3 users and these users have 1,2,3 as a User_Id PK.

Apparently I used the relational mode that phpMyAdmin offers me but there's no result.

What can i do?

Upvotes: 0

Views: 781

Answers (3)

Mayuri
Mayuri

Reputation: 412

MyISAM table doesn't support Foreignkey and it only supports Primary key. But you can convert it into InnoDB table and then you can assign Foreign key to it.

Upvotes: 0

Wireblue
Wireblue

Reputation: 1509

The table you created is an MyISAM table and unfortunately they don't support Foreign Keys.

http://www.sitepoint.com/mysql-myisam-table-pros-con/

In PHPMyAdmin you can easily convert it from an MyISAM to an InnoDB table. This should enable the foreign Key features you're after.

Upvotes: 2

QuentinB
QuentinB

Reputation: 133

When you say :

phpMyAdmin doesn't allow to insert foreign keys, the problem comes when i try to insert a follower based on the USERS table.

What type of error do you get? Could you give us more information?

Upvotes: 1

Related Questions