为什么我设置了某个字段类型为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()
{
//
}
}
你根本就没用Model来做数据库的操作,和timestamps是否是
CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
的设置无关Laravel 是 5.1+
Laravel是建议表名是复数的,你的表名应该为
equips
Laravel要求主键,并且名字建议为id,你的主键换名字了
要new 一个Model文件
这个类会自动指向
equips
表操作
你如果是这么弄的,Laravel仍然没有自动维护
created_at
updated_at
我把头给你当凳子坐,毕竟我用Laravel都2年多了,不关闭timestamps,是不可能出现你的情况的