时间戳正在插入0个值

时间:2015-10-03 18:01:14

标签: php laravel timestamp

我不明白为什么我的时间戳没有价值......

patient_data迁移文件

 public function up()
    {
        Schema::create('patients', function (Blueprint $table) {

            $table->increments('pID');
            $table->string('pName');
            $table->string('pAddress');
            $table->string('pBday');
            $table->string('pPhone');
            $table->string('pEcon');
            $table->timestamps();
        });
    }

我的数据库

enter image description here

我将created_at列更改为pDreg

我检查了所有内容并且我确信我的代码是正确的...但我仍然没有得到任何价值

2 个答案:

答案 0 :(得分:1)

如果时间戳列应设置为当前日期和时间,则应使用CURR_TIMESTAMP作为默认值,phpmyadmin会将此选项作为默认值下拉列表中的一个选项。

<强> SQL

ALTER TABLE `table` MODIFY `column` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;

这会将列设置为TIMESTAMP的类型,当您插入表格时,字段会自动设置为当前时间戳。

答案 1 :(得分:1)

您的字段类型设置为DATETIME(这就是为什么会显示如何显示的日期),如果您想使用unix时间戳作为字段的值,则应将其更改为INT。 否则你应该使用MySQL函数NOW()来表示当前的日期和时间(或$ table-&gt; string(日期('Ymd H:i:s'));如果你更喜欢使用PHP,那么。