[英]Invalid datetime format: 1366 Incorrect integer value
我正在使用 Laravel 8 來開發我的項目,並且我已經進行了此遷移:
public function up()
{
Schema::create('activation_codes', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->string('code');
$table->boolean('used')->default(false);
$table->dateTime('expire');
$table->timestamps();
});
}
在 Model 我添加了這個:
protected $fillable = ['user_id','code','used','expire'];
public function scopeCreateCode($query, $user)
{
$code = $this->code();
return $query->create([
'user_id' => $user,
'code' => $code,
'expire' => Carbon::now()->addMinute(15)
]);
}
private function code()
{
do{
$code = Str::random(60);
$checkCode = static::whereCode($code)->get();
}while(!$checkCode->isEmpty());
return $code;
}
但是每當我運行它時,我都會收到此錯誤:
SQLSTATE [22007]:無效的日期時間格式:1366 不正確的 integer 值
那么這里出了什么問題? 我該如何解決這個問題?
更新:
1 id Primary bigint(20) UNSIGNED No None AUTO_INCREMENT
2 user_id Index bigint(20) UNSIGNED
3 code varchar(255)
4 used tinyint(1) No 0
5 expire datetime No None
6 created_at timestamp Yes NULL
7 updated_at timestamp Yes NULL
錯誤捕獲:
你的代碼是正確的。 您能否再次檢查您的數據庫的時間戳並過期類型 DateTime 或 Date
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.