ALTER query on every start with a CURRENT_TIMESTAMP default in MySQL
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
When connecting to a MySQL database with default: () => 'CURRENT_TIMESTAMP'
on one of the properties, the column will receive an ALTER query.
https://gist.github.com/Ionaru/6744272f96b122eda1abbdf8d46131d1
Queries that are executed when running the script:
START TRANSACTION
SELECT DATABASE() AS `db_name`
SELECT * FROM `INFORMATION_SCHEMA`.`TABLES` WHERE (`TABLE_SCHEMA` = 'web_evetrack_test_2' AND `TABLE_NAME` = 'bar')
SELECT * FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE (`TABLE_SCHEMA` = 'web_evetrack_test_2' AND `TABLE_NAME` = 'bar')
SELECT * FROM `INFORMATION_SCHEMA`.`KEY_COLUMN_USAGE` WHERE `CONSTRAINT_NAME` = 'PRIMARY' AND ((`TABLE_SCHEMA` = 'web_evetrack_test_2' AND `TABLE_NAME` = 'bar'))
SELECT `SCHEMA_NAME`, `DEFAULT_CHARACTER_SET_NAME` as `CHARSET`, `DEFAULT_COLLATION_NAME` AS `COLLATION` FROM `INFORMATION_SCHEMA`.`SCHEMATA`
SELECT `s`.* FROM `INFORMATION_SCHEMA`.`STATISTICS` `s` LEFT JOIN `INFORMATION_SCHEMA`.`REFERENTIAL_CONSTRAINTS` `rc` ON `s`.`INDEX_NAME` = `rc`.`CONSTRAINT_NAME` WHERE ((`s`.`TABLE_SCHEMA` = 'web_evetrack_test_2' AND `s`.`TABLE_NAME` = 'bar')) AND `s`.`INDEX_NAME` != 'PRIMARY' AND `rc`.`CONSTRAINT_NAME` IS NULL
SELECT `kcu`.`TABLE_SCHEMA`, `kcu`.`TABLE_NAME`, `kcu`.`CONSTRAINT_NAME`, `kcu`.`COLUMN_NAME`, `kcu`.`REFERENCED_TABLE_SCHEMA`, `kcu`.`REFERENCED_TABLE_NAME`, `kcu`.`REFERENCED_COLUMN_NAME`, `rc`.`DELETE_RULE` `ON_DELETE`, `rc`.`UPDATE_RULE` `ON_UPDATE` FROM `INFORMATION_SCHEMA`.`KEY_COLUMN_USAGE` `kcu` INNER JOIN `INFORMATION_SCHEMA`.`REFERENTIAL_CONSTRAINTS` `rc` ON `rc`.`constraint_name` = `kcu`.`constraint_name` WHERE (`kcu`.`TABLE_SCHEMA` = 'web_evetrack_test_2' AND `kcu`.`TABLE_NAME` = 'bar')
ALTER TABLE `bar` CHANGE `lastLogin` `lastLogin` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
COMMIT
Edit Loks like this is an issue with the Date type field as a whole, the same ALTER query behaviour is happening with this column:
@Column({
nullable: true,
})
public lastLogin?: Date;
...
ALTER TABLE `bar` CHANGE `tokenExpiry` `tokenExpiry` datetime NULL
COMMIT
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
11.2.5 Automatic Initialization and Updating for TIMESTAMP ...
With an ON UPDATE CURRENT_TIMESTAMP clause but no DEFAULT clause, the column is automatically updated to the current timestamp but does not have...
Read more >How to alter column to set default CURRENT_TIMESTAMP in ...
You can't assign a DATE datatype column with a CURRENT_TIMESTAMP default value. Just go with Jim's solution and do your query to something...
Read more >Implementing DEFAULT CURRENT_TIMESTAMP and ON ...
With the DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP, a column has the current timestamp for its default value and is ...
Read more >How to Update to CURRENT_TIMESTAMP in MySQL?
Syntax – Update value to Current Timestamp · ALTER TABLE table_name updates table schema. · CHANGE column_name updates the column to. · column_name...
Read more >Can't default date to CURRENT_TIMESTAMP in MySQL 5.5
2 Answers 2 · Upgrade to MySQL 5.6.5 · Change the column type to TIMESTAMP, as in: ALTER TABLE `downloads` ADD `date` TIMESTAMP...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, tested on a wrong branch. Should be fixed after #3262 is merged.
If that’s the case please open a new issue with more details.