时间戳正在插入 0 个值
timestamps is inserting 0 values
我不明白为什么我的时间戳没有价值...
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();
});
}
我的数据库
我将 created_at 列更改为 pDreg
我检查了一切,我相信我的代码是正确的..但我仍然没有得到任何值
如果时间戳列应设置为当前日期和时间,则应使用 CURR_TIMESTAMP
作为默认值,phpmyadmin 在默认值下拉列表中提供了此选项。
SQL
ALTER TABLE `table` MODIFY `column` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;
这会将列设置为 TIMESTAMP 类型,并且当您插入 table 时,字段会自动设置为当前时间戳。
您的字段类型设置为 DATETIME(这就是为什么显示 0000-00-00 之类的日期),如果您想使用 unix 时间戳作为字段的值,您应该将其更改为 INT。
否则,您应该使用 MySQL 函数 NOW() 获取当前日期和时间(或 $table->string(date('Y-m-d H:i:s'));如果您更喜欢使用 PHP)。
我不明白为什么我的时间戳没有价值...
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();
});
}
我的数据库
我将 created_at 列更改为 pDreg
我检查了一切,我相信我的代码是正确的..但我仍然没有得到任何值
如果时间戳列应设置为当前日期和时间,则应使用 CURR_TIMESTAMP
作为默认值,phpmyadmin 在默认值下拉列表中提供了此选项。
SQL
ALTER TABLE `table` MODIFY `column` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;
这会将列设置为 TIMESTAMP 类型,并且当您插入 table 时,字段会自动设置为当前时间戳。
您的字段类型设置为 DATETIME(这就是为什么显示 0000-00-00 之类的日期),如果您想使用 unix 时间戳作为字段的值,您应该将其更改为 INT。 否则,您应该使用 MySQL 函数 NOW() 获取当前日期和时间(或 $table->string(date('Y-m-d H:i:s'));如果您更喜欢使用 PHP)。