gpt4 book ai didi

php - Laravel 与 SQL Server 2008 抛出 "Conversion of a varchar data type to a datetime data type resulted in an out-of-range value"

转载 作者:可可西里 更新时间:2023-11-01 14:01:21 24 4
gpt4 key购买 nike

我在 SQL Server 2008 中使用 laravel 4.1

我创建了一个基于 Eloquent orm 的带有时间戳的模型:

class Attendance extends \Eloquent {

protected $table = 'Attendance';

public function users(){return $this->belongsToMany('User', 'Users_Attendance', 'user_id', 'attendance_id');}

}

当我尝试插入新字段时:

public function postAttendanceUsers() {
$attendance = new Attendance;
$attendance->user_id = Auth::user()->id;
$attendance->save();
}

显示如下错误:

SQLSTATE[22007]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server] Conversion of a varchar data type to a datetime data type resulted in an out-of-range value. (SQL: insert into [Attendance] ([user_id], [updated_at], [created_at]) values (40, 2015-08-27 12:28:42.000, 2015-08-27 12:28:42.000))

最佳答案

我创建了一个具有以下格式的新方法:

 /**
* Get the format for database stored dates.
*
* @return string
*/
public function getDateFormat() {
return 'Y-d-m H:i:s';
}

我希望有人有用

关于php - Laravel 与 SQL Server 2008 抛出 "Conversion of a varchar data type to a datetime data type resulted in an out-of-range value",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32253955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com