mysql - 在没有主键的情况下编辑 MySQL 数据库中的数据

标签 mysql webmin

我在 Idaq 托管包上使用 Webmin 来管理我的 MySQL 数据库。我从以前的主机导入了数据库,现在发现我无法更改特定表中的任何数据,因为出现错误“无法编辑此表中的数据,因为它没有主键。”

在 php 脚本中,我可以更改数据,但确实需要从控制面板更改它。

当我尝试创建主键字段时,出现以下错误“无法保存字段:SQL alter table userbase add referenceNumber smallint not null auto_increment failed : Incorrect表定义,auto列只能有一个,必须定义为key"

我很清楚任何表都应该包含一个主键,这是我的错误,但是有人可以提供一些帮助吗?

最佳答案

因为你没有同时将它设置为key所以它没有通过并且它必须被定义为key部分,把key放在最后。

使用

ALTER TABLE tableName ADD autoIncrementColumn MEDIUMINT NOT NULL AUTO_INCREMENT KEY

Johan 在评论中提供的额外信息

@Mick, To add to PEZ's answer, if you do not provide a primary key, MySQL adds a hidden primary integer autoincrement key. In order to override the hidden key, the alter table statement must specify the addition of a new field and the assignment of the new PK in the same line, otherwise the hidden PK will block the alteration.

关于mysql - 在没有主键的情况下编辑 MySQL 数据库中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7191480/

相关文章:

sql - 为什么我在 Postgresql psql :/lib64/libpq. so.5 : no version information available (required by psql)? 上不断收到此错误

mysql - org.hibernate.MappingException : Unknown entity SessionFactoryImpl. getEntityPersister

mysql - 无法让 SQL 查询使用语法错误的变量 b/c

mysql - 从 linux mint 完全卸载 mysql

linux - 如何修复 "E: The list of sources could not be read"无法读取错误?

linux - 如何在我的 Google Cloud Ubuntu 实例上设置我的用户密码?

php - 拆分此 sql 查询,以便它可以像在工作台上一样在 php 上运行

mysql - 在 MySQL 中,为什么在使用未提交读时从 select 设置变量会获取锁?

mysql - 为什么导入的数据库在 phpmyadmin 中较小?

mysql - 注 - 用户 'root' @'localhost' 的访问被拒绝(使用密码 : NO) appearing in mysql error. 日志