3

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.

asked Mar 2, 2017 at 11:42
1

3 Answers 3

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();
answered Mar 2, 2017 at 12:30
0
3

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"

answered Mar 2, 2017 at 12:10
1

You have to use below code after TIMESTAMP:

NOT NULL DEFAULT CURRENT_TIMESTAMP
7ochem
7,61516 gold badges54 silver badges82 bronze badges
answered Mar 2, 2017 at 12:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.