gpt4 book ai didi

mysql - Laravel迁移: Using storedAs() (generated colum) with subtime() MySQL function

转载 作者:行者123 更新时间:2023-11-29 17:19:45 38 4
gpt4 key购买 nike

这是我在迁移中的 up() 方法

$table->dateTimeTz('from');
$table->time('expire_by_time')->default('0:30:00');

$expression = 'subtime(\'from\', \'expire_by_time\')';
$table->dateTimeTz('expire_at')->storedAs($expression);

我所拥有的是一个从 from 开始的事件,但我希望它在开始前 30 分钟(或一小时,或 50 小时...)“过期”。稍后在我的代码中,我可以使用这个新生成的 expire_at 列进行显示或排序。

但是,由于某种原因,这不起作用,我不断收到 expired_at 列的 0000-00-00 00:00:00

+-------+---------------------+----------------+---------------------+
| id | from | expire_by_time | expire_at |
+-------+---------------------+----------------+---------------------+
| 11111 | 2019-09-29 12:00:00 | 00:30:00 | 0000-00-00 00:00:00 |
+-------+---------------------+----------------+---------------------+

我在这里做(错)了什么?

最佳答案

我不知道如何转义字符。这:

$expression = 'subtime(\'from\', \'expire_by_time\')';

应该是这样的:

$expression = 'subtime(`from`, `expire_by_time`)';

现在我明白了:

+-------+---------------------+----------------+---------------------+
| id | from | expire_by_time | expire_at |
+-------+---------------------+----------------+---------------------+
| 11111 | 2019-09-29 12:00:00 | 00:30:00 | 2019-09-29 11:30:00 |
+-------+---------------------+----------------+---------------------+

关于mysql - Laravel迁移: Using storedAs() (generated colum) with subtime() MySQL function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51327166/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com