MySQL 默认日期时间通过 phpmyadmin

MySQL default datetime through phpmyadmin(MySQL 默认日期时间通过 phpmyadmin)
本文介绍了MySQL 默认日期时间通过 phpmyadmin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在现有数据库中,我有年龄列 (INT).现在我需要将它设置为 dob (DATETIME).

我尝试通过 PHPMyAdmin 这样做,将 CURRENT_TIMESTAMP 作为 查看区别.

词来自 this 博客

数据类型规范中的 DEFAULT value 子句指示列的默认值.除了一个例外,默认值必须是一个常量;它不能是函数或表达式.

这意味着,例如,您不能将日期列的默认值设置为 NOW() 或 CURRENT_DATE 等函数的值.

例外情况是您可以将 CURRENT_TIMESTAMP 指定为 TIMESTAMP 列的默认值.

In an existing database, I've age column (INT). Now I need to set it as dob (DATETIME).

I try doing so through PHPMyAdmin, giving CURRENT_TIMESTAMP as default value as defined by answer with 138 upvotes. However PHPMyAdmin is complaining #1067 - invalid default value for 'dob' as in attached screenshot:

Can someone please suggest why I'm getting that error and how to fix that?

解决方案

You can't set CURRENT_TIMESTAMP as default value with DATETIME.

But you can do it with TIMESTAMP.

See the difference here.

Words from this blog

The DEFAULT value clause in a data type specification indicates a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression.

This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE.

The exception is that you can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP column.

这篇关于MySQL 默认日期时间通过 phpmyadmin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)