I am upgrading my table with new version and changed config version too,
getting error :PDOException Object ( [message:protected] => SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 [string:Exception:private] => [code:protected] => 42000
here is my query :
<?php
$installer = $this;
$installer->startSetup();
$installer->run("ALTER TABLE `asm_tracker` CHANGE COLUMN `create_at` TIMESTAMP;");
$installer->run("ALTER TABLE `asm_tracker` CHANGE COLUMN `punch_in_time` TIMESTAMP;");
$installer->run("ALTER TABLE `asm_tracker` CHANGE COLUMN `punch_out_time` TIMESTAMP;");
$installer->run("ALTER TABLE `asm_tracker` ADD `manager_name` varchar(30) NOT NULL ;");
$installer->endSetup();
?>
want to change DATATYPE and add one column in existing table.
-
This answer will help you magento.stackexchange.com/questions/92935/…Jalpesh Patel– Jalpesh Patel2017年03月02日 11:54:39 +00:00Commented Mar 2, 2017 at 11:54
3 Answers 3
Try this :
$installer = $this;
$installer->startSetup();
$installer->run("ALTER TABLE `asm_tracker` CHANGE `create_at` `create_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;");
$installer->run("ALTER TABLE `asm_tracker` CHANGE `punch_in_time` `punch_in_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;");
$installer->run("ALTER TABLE `asm_tracker` CHANGE `punch_out_time` `punch_out_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;");
$installer->run("ALTER TABLE `asm_tracker` ADD `manager_name` varchar(30) NOT NULL;");
$installer->endSetup();
Try below code:
$installer = $this;
$installer->startSetup();
$installer->run("ALTER TABLE `asm_tracker` CHANGE `create_at` `create_at` TIMESTAMP;");
$installer->run("ALTER TABLE `asm_tracker` CHANGE `punch_in_time` `punch_in_time` TIMESTAMP;");
$installer->run("ALTER TABLE `asm_tracker` CHANGE `punch_out_time` `punch_out_time` TIMESTAMP;");
$installer->run("ALTER TABLE `asm_tracker` ADD `manager_name` varchar(30) NOT NULL;");
$installer->endSetup();
Note: Please add "NOT NULL DEFAULT CURRENT_TIMESTAMP"
You have to use below code after TIMESTAMP:
NOT NULL DEFAULT CURRENT_TIMESTAMP