I was wondering if anyone could help me.
I have weird behavior when issuing an ALTER command. The command comes from MySQL Workbench synchronization, and it fails. I have a table with fields:
`id` int(11) NOT NULL AUTO_INCREMENT , `text` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL , `updated` datetime NULL DEFAULT NULL , `remote_addr` varchar(45) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL , `http_user_agent` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL , `user_id` int(11) NULL DEFAULT NULL , `category` varchar(20) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL , `created` datetime NULL DEFAULT NULL , PRIMARY KEY (`id`)
And I want to issue the ALTER command:
ALTER TABLE `logs` ADD COLUMN `updated` DATETIME NULL DEFAULT NULL AFTER `created`, CHANGE COLUMN `created` `created` DATETIME NULL DEFAULT NULL AFTER `category`
I get in response:
Unknown column 'created' in 'logs'
But
ALTER TABLE `logs` ADD COLUMN `updated` DATETIME NULL DEFAULT NULL AFTER `created`
works on its own, and:
ALTER TABLE `logs` CHANGE COLUMN `created` `created` DATETIME NULL DEFAULT NULL AFTER `category`
also works on its own.
I do not understand why, when both of them are combined in one request, this does not work and says that "created" does not exist. I know that it definitely exists.
Note that the change column for 'created' does not bother me; it is generated by MWB when comparing and preparing for synchronization. But it was just interesting why both actions could not be applied to the same query.
I am using MySQL 5.5.8
Refresh
I can really do a few articles in order. I do it on other tables just fine.
I forgot to mention this. But when I delete the AFTER part, it works.
So this does not work:
ALTER TABLE `logs` ADD COLUMN `updated` DATETIME NULL DEFAULT NULL AFTER `created`, CHANGE COLUMN `created` `created` DATETIME NULL DEFAULT NULL AFTER `category`
But it does:
ALTER TABLE `logs` ADD COLUMN `updated` DATETIME NULL DEFAULT NULL, CHANGE COLUMN `created` `created` DATETIME NULL DEFAULT NULL AFTER `category`