栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

MySQL 1062

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

MySQL 1062

在mysql控制台中运行以下查询:

SHOW CREATE TABLE momento_distribution

检查看起来像这样的行

ConSTRAINT `momento_distribution_FK_1` FOREIGN KEY (`momento_id`) REFERENCES `momento` (`id`)

可能会有所不同,我只是猜测可能会是什么。如果您在’momento_id’和’momento_idmember’上都具有外键,则将获得两个外键名称。下一步是删除外键。运行以下查询:

ALTER TABLE momento_distribution DROP FOREIGN KEY momento_distribution_FK_1ALTER TABLE momento_distribution DROP FOREIGN KEY momento_distribution_FK_2

确保将外键名称更改为您从

CREATETABLE
查询中获得的名称。现在,您没有任何外键,因此可以轻松删除主键。请尝试以下操作:

ALTER TABLE  `momento_distribution` DROP PRIMARY KEY

添加所需的列,如下所示:

ALTER TABLE  `momento_distribution` ADD  `id` INT( 11 ) NOT NULL  PRIMARY KEY AUTO_INCREMENT FIRST

该查询还会添加数字,因此您无需依赖@rowid。现在,您需要将外键添加回前面的列。为此,首先创建以下索引:

ALTER TABLE  `momento_distribution` ADD INDEX (  `momento_id` )ALTER TABLE  `momento_distribution` ADD INDEX (  `momento_idmember` )

现在添加外键。根据需要更改参考表/列:

ALTER TABLE  `momento_distribution` ADD FOREIGN KEY ( `momento_id`) REFERENCES  `momento` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT ALTER TABLE  `momento_distribution` ADD FOREIGN KEY ( `momento_idmember`) REFERENCES  `member` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT

希望能有所帮助。如果您遇到任何错误,请使用参考表的结构以及所得到的错误代码来编辑问题。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/383763.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号