Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望把timestamp类型加入到 “强制非text,blob,json类型字段必须为NOT NULL”的类型中 #411

Closed
gufei opened this issue Dec 8, 2020 · 6 comments

Comments

@gufei
Copy link

gufei commented Dec 8, 2020

有时候做软删除时,软删除字段使用timestamp类型,但默认值需要为NULL,希望把时间类型加入到
“强制非text,blob,json类型字段必须为NOT NULL”
的类型中去

@cookieY
Copy link
Owner

cookieY commented Dec 9, 2020

你需要null 但是强制NOT null .....

@gufei
Copy link
Author

gufei commented Dec 9, 2020

是的,这个类型的默认值需要为NULL,但是别的还是需要检查不能为NULL的

@wzming
Copy link

wzming commented Dec 11, 2020

这个的确遇到到了,时间类型为null是有业务意义存在的,比如说收货时间,确认收货时间等等,现在设置了字段必须not null ,搞得遇到,有这种字段的表还是要跳过yearning去处理

@cookieY
Copy link
Owner

cookieY commented Dec 11, 2020

感谢反馈,会在后面的版本中完善

@loodeer
Copy link

loodeer commented Mar 30, 2021

已经看到 2.3.2 版本支持了 TIMESTAMP 字段类型可以为 NULL,感谢 @cookieY
我遇到一个差不多的问题,故借楼反馈,希望可以得到解决。

目前 yearning 仅支持 CURRENT_TIMESTAMP 作为 TIMESTAMP 的默认值。
我们业务上使用的 '0000-00-00 00:00:00' 作为 TIMESTAMP 的默认值来代表无该时间的业务含义。
而 '0000-00-00 00:00:00' 作为特殊的零值,是可以作为 TIMESTAMP 的默认值的。

参考官方文档:

MySQL does not accept TIMESTAMP values that include a zero in the day or month column or values that are not a valid date. The sole exception to this rule is the special “zero” value '0000-00-00 00:00:00', if the SQL mode permits this value.

11.2.2 The DATE, DATETIME, and TIMESTAMP Types

CREATE TABLE t1 (ts TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00');

11.2.5 Automatic Initialization and Updating for TIMESTAMP and DATETIME

@cookieY
Copy link
Owner

cookieY commented Mar 30, 2021

@loodeer https://github.com/cookieY/Yearning/releases/tag/2.3.2.1

@cookieY cookieY closed this as completed Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants