php - 为什么时间戳 col 为空
问题描述
我将时间戳 cols 添加到数据库表中,
public function up()
{
Schema::table('allestates', function (Blueprint $table) {
$table->timestamps();
});
}
并且还真实地融入了表格的模型。
public $timestamps = true;
protected $table = "allestates";
解决方案
Timestamps 为 null 是因为您在插入数据时可能没有使用 laravel eloquent。
$model= new model;
$model->column_one= 'John';
$model->save();
或者你可以使用,
$table->timestamp('created_at')->default(\DB::raw('CURRENT_TIMESTAMP'));
$table->timestamp('updated_at')->default(\DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
推荐阅读
- puppeteer - 当我打开新标签页或窗口时,如何保持 Puppeter 会话?
- reactjs - 如何从 API 数组中获取第一个元素
- javascript - Vue js 不改变路由——vue 路由不起作用
- export - 审核来自 Dynamics 365 的导出
- azure-active-directory - MS Graph api 用户身份验证失败
- ios - 什么时候应该在 iOS 应用中删除 authStateDidChangeListener?
- vue.js - Quasar q-tabs:如何通过代码动态显示/隐藏 q-tab?
- android - 如何将 Fiddler 设置为 Android 设备的代理?
- python - 如果有重复,如何找到列表元素的最大索引?
- c++ - 将“operator>”委托给“operator<”是不好的形式吗?