简体   繁体   English

phpMyAdmin外键下拉字段值

[英]phpMyAdmin foreign key drop-down field values

I'm using phpmyadmin ( php & mysql ) and I'm having a lot of trouble linking the tables using foreign keys. 我正在使用phpmyadmin( phpmysql ),我在使用外键链接表时遇到了很多麻烦。

I'm getting negative values for the field countyId (which is the foreign key). 我得到字段countyId (这是外键)的负值。 However it is linking to my other table fine and it's cascading fine. 然而,它链接到我的其他表罚款,它的级联很好。

When I go to add data there will be a drop box for the CountyId and the values look something like this, 当我去添加数据时,将会有一个CountyId的下拉框,值看起来像这样,

-1

1-

Here is my alter statement: 这是我的修改声明:

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

As i explained on ServerFault : 正如我在ServerFault上解释的那样:

It is not negaitve number, the feature of phpMYAdmin is to show foreign key value and a custom description field next to it. 它不是负数,phpMYAdmin的功能是显示外键值和旁边的自定义描述字段。 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). 在引用的表(Counties)中,您可以转到“关系视图”,在表格下方有一个选择框“选择要显示的字段”,您可以在其中选择将在引用表中显示在CountyID值旁边的值(Baronies )。 Also see: phpymadminWiki 另见: phpymadminWiki

You can change the look of this dropdown using the ForeignKeyDropdownOrder option. 您可以使用ForeignKeyDropdownOrder选项更改此下拉列表的外观。 (See the PMA documentation ). (参见PMA文档 )。

Example: 例:

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

As Lex said, this is just the way phpMyAdmin displays the values. 正如Lex所说,这就是phpMyAdmin显示值的方式。 If you see "-1" or "1-" in that dropdown box, it's just 1. 如果您在该下拉框中看到“-1”或“1-”,则它只是1。

进行操作而不是将myiasm更改为innoDB而不是Go

Check if your tables use MyIsam engine. 检查您的表是否使用MyIsam引擎。 In that case foreign keys are not supported. 在这种情况下,不支持外键。 Use InnoDB instead. 请改用InnoDB。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM