MySQL phpMyAdmin 中没有唯一列的表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21581543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:59:46  来源:igfitidea点击:

Table with no unique column in phpMyAdmin

mysqlphpmyadmin

提问by Peeech

Here is my table:

这是我的表:

CREATE TABLE group_edits (
  vfile_id bigint(20) unsigned NOT NULL,
  editor_id int(10) unsigned NOT NULL,
  edits text
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

There is no unique index, because one editor_id can edit multiple vfile_ids, also one vfile_id can be edited by multiple editor_ids.

没有唯一索引,因为一个editor_id可以编辑多个vfile_id,一个vfile_id也可以被多个editor_id编辑。

phpMyAdmin 4.1.6 does not allow me to edit this table saying:

phpMyAdmin 4.1.6 不允许我编辑这个表说:

Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available.

Now it makes me thing is there anything wrong with the table like this? Rows are unique when you take a value of editor_id AND vfile_id while none of the columns alone is unique.

现在它让我觉得像这样的桌子有什么问题吗?当您采用 editor_id AND vfile_id 的值时,行是唯一的,而单独的列都不是唯一的。

I know that to fix it I could add

我知道要修复它我可以添加

`ID` int(11) NOT NULL AUTO_INCREMENT,

but it does not reflect the design of my database schema and I would like to avoid adding tricks just to make phpMyAdmin work.

但它不反映我的数据库架构的设计,我想避免添加技巧只是为了使 phpMyAdmin 工作。

Is my database design wrong or is it phpMyAdmin?

是我的数据库设计错误还是 phpMyAdmin?

回答by O. Jones

If you are absolutely sure you can make a unique primary compound key of (editor_id, vfile_id), go ahead and do that.

如果您绝对确定可以为 (editor_id, vfile_id) 创建唯一的主复合键,请继续执行此操作。

 ALTER TABLE group_edits ADD PRIMARY KEY (editor_id, vfile_id)

You'd be wise to use phpmyadmin to dump a copy of the table first, so you can restore it if you mess it up.

明智的做法是先使用 phpmyadmin 转储该表的副本,以便在弄乱它时可以恢复它。

That should permit phpmyadmin to let you update rows in the table.

这应该允许 phpmyadmin 让您更新表中的行。