通过phpmyadmin的MySQL默认日期时间 [英] MySQL default datetime through phpmyadmin

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

问题描述

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

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

我尝试通过PHPMyAdmin这样做,将CURRENT_TIMESTAMP设为

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.

但是您可以使用TIMESTAMP来做到这一点.

But you can do it with TIMESTAMP.

此处中查看区别.

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

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.

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

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.

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

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆