views:

500

answers:

4

Hey guys i'm using phpmyadmin (php & mysql) and i'm having alot of trouble linking the tables using foreign keys.

I'm getting negative values for the field countyId (which is the foriegn key). However it is linking to my other table fine and it's cascading fine.

So when I go to add data there will be a drop box for the CountyId and the values will look something like this,

" -1

1- "

Here is my alter statement,

ALTER TABLE Baronies
ADD FOREIGN KEY (CountyId)
REFERENCES Counties (CountyId)
ON DELETE CASCADE
A: 

Check if your tables use MyIsam engine. In that case foreign keys are not supported. Use InnoDB instead.

munissor
Yeah both tables are using InnoDB engine.
Alan
phpmyadmin uses MyIsame by default is there anyway to change this? I've tried looking but haven't found anything.Cause i've just been changing the tables to InnoDB....could this be the problem?
Alan
The default in mySql is myISAM, this is not a phpmyadmin option.Check on the MySql documentation about the DB engines at: http://dev.mysql.com/doc/refman/5.1/en/storage-engines.html
munissor
To change the default engine use the option default-storage-engine=InnoDB on your my.cnf file
munissor
+1  A: 

You can change the look of this dropdown using the ForeignKeyDropdownOrder option. (See the PMA documentation).

Example:

$cfg['ForeignKeyDropdownOrder'] = array( 'content-id');
/* 'content' is the referenced data, 'id' is the key value. */
eugene y
+1  A: 

As Lex said, this is just the way phpMyAdmin displays the values. If you see "-1" or "1-" in that dropdown box, it's just 1.

Travis Beale
A: 

As i explained on ServerFault:

It is not negaitve number, the feature of phpMYAdmin is to show foreign key value and a custom description field next to it. In the referenced table (Counties) you can go to "Relation view" and under the table there is a select box "Choose field to display", in which you choose value that will be displayed next to CountyID value in the referencing table (Baronies). Also see: phpymadminWiki

Odin