为什么我设置了某个字段类型为timestamps,但是他并没有像我预期的一样在更新或者添加的时候自动填充当前时间戳?
还有我用Laravel的migrate生成的数据表也一样,生成的表里面那个timestamps字段根本不起效果。是怎么回事?
这是migration文件
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateEquip extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('equip', function (Blueprint $table) {
// $table->increments('id');
$table->smallInteger('equip_id')->unsigned()->comment('装备id');
$table->string('eqiup_name')->comment('装备名称');
$table->string('eqiup_desc')->comment('装备描述');
$table->timestamps();
$table->primary('equip_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你根本就没用Model来做数据库的操作,和timestamps是否是
CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP的设置无关Laravel 是 5.1+
Laravel是建议表名是复数的,你的表名应该为
equipsLaravel要求主键,并且名字建议为id,你的主键换名字了
要new 一个Model文件
这个类会自动指向
equips表操作
你如果是这么弄的,Laravel仍然没有自动维护
created_atupdated_at我把头给你当凳子坐,毕竟我用Laravel都2年多了,不关闭timestamps,是不可能出现你的情况的
你设置timestamp 字段
ON UPDATE CURRENT_TIMESTAMP了吗laravel设置下默认值
谢邀。
默认 Eloquent 会自动维护数据库表的
created_at和 updated_at 字段。只要把这两个「时间戳」字段加到数据库表, Eloquent 就会处理剩下的工作。如果不想让 Eloquent 自动维护这些字段,把下面的属性加到模型类里: