我一直在互联网上寻找解决方案,但是我似乎无法弄清楚我真正的基本编码知识有什么问题...
谁能告诉我这是怎么了?
ALTER TABLE `groups`
ADD COLUMN `forum_enabled` enum('0','1') CHARACTER SET latin1 COLLATE
latin1_swedish_ci NOT NULL DEFAULT '0' AFTER `admindeco`;
ALTER TABLE `user_badges`
ADD UNIQUE INDEX `user_id, badge_id`;
ALTER TABLE `furniture`
ADD COLUMN`behaviour_data` int(11) NOT NULL DEFAULT 0 AFTER
`interaction_type`;
ALTER TABLE `users`
MODIFY COLUMN `rank_vip` int(1) NULL DEFAULT 1 AFTER `rank`;
ALTER TABLE `server_settings`
CHANGE COLUMN `variable` `key` varchar(255) CHARACTER SET latin1 COLLATE
latin1_swedish_ci NOT NULL DEFAULT 'server.variable' FIRST ;
ALTER TABLE `catalog_deals`
DROP COLUMN `page_id`,
DROP COLUMN `cost_credits`,
DROP COLUMN `cost_pixels`,
MODIFY COLUMN `items` text CHARACTER SET latin1 COLLATE
latin1_swedish_ci
NOT NULL AFTER `id`,
ADD COLUMN `room_id` int(11) NOT NULL AFTER `name`;
SET FOREIGN_KEY_CHECKS=0;
我遇到以下错误:
SQL查询:ALTER TABLE组将列添加到forum_enabled ENUM('0','1')字符集latin1 COLLATE latin1_swedish_ci NOT NULL默认admindeco后为'0'; MySQL说:文档#1060-重复的列名'forum_enabled'
感谢进阶!
答案 0 :(得分:0)
从错误消息来看,您试图在第一条语句中添加的列似乎已存在于表中。
一种简单的解决方案是在添加列之前先删除它,例如:
ALTER TABLE `groups`
DROP COLUMN `forum_enabled`;
这可以与ADD
命令结合在一个语句中,例如:
ALTER TABLE `groups`
DROP COLUMN `forum_enabled`,
ADD COLUMN `forum_enabled` enum('0','1') ...
;
还可以动态检查一列是否存在,然后在需要时将其删除,例如:
IF EXISTS (
SELECT 1
FROM information_schema.columns
WHERE
table_name = 'groups'
AND column_name = 'forum_enabled'
AND table_schema = DATABASE()
) THEN
ALTER TABLE `groups`
DROP COLUMN `forum_enabled`;
END IF;