【发布时间】:2020-09-02 11:07:03
【问题描述】:
我想通过 Laravel 制作 Rest API, 我是为了创造假数据 我在迁移过程之后,在数据库播种过程中遇到了这个问题,,
php artisan migrate:fresh
当我在终端中点击这个命令时,一切都很好并成功迁移
但是当我点击这个命令时问题就在这里
php artisan db:seed
还有错误
Carbon\Exceptions\InvalidFormatException
Could not parse '1': DateTime::__construct(): Failed to parse time string (1) at position 0 (1): Unexpected character
at vendor/nesbot/carbon/src/Carbon/Traits/Creator.php:188
184| } catch (Exception $exception) {
185| $date = @static::now($tz)->change($time);
186|
187| if (!$date) {
> 188| throw new InvalidFormatException("Could not parse '$time': ".$exception-
getMessage(), 0, $exception);
189| }
190|
191| return $date;
192| }
1 [internal]:0
Illuminate\Database\Eloquent\FactoryBuilder::Illuminate\Database\Eloquent\{closure}()
+1 vendor frames
3 [internal]:0
Illuminate\Database\Eloquent\FactoryBuilder::Illuminate\Database\Eloquent\{closure}()
我会拍照了解详情
更新::
将'email_verified_at' => $faker->randomElement 更改为'email_verified_at' => $faker->dateTime
收到此错误
Illuminate\Database\QueryException
SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'email_verified_at' at row 1 (SQL: insert into `users` (`first_name`, `last_name`, `email`, `email_verified_at`, `mobile`, `mobile_verified_at`, `password`, `remember_token`, `updated_at`, `created_at`) values (Salvador, Reynolds, smith.jarred@example.org, 1973-06-05 00:00:00, 1-489-345-8354 x338, 1973-06-02, $2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi, OBAqyXgPHJ, 2020-05-17 01:11:56, 2020-05-17 01:11:56))
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {
> 671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
+16 vendor frames
17 database/seeds/DatabaseSeeder.php:15
Illuminate\Database\Eloquent\FactoryBuilder::create()
【问题讨论】:
-
您在播种工厂时是否传递了日期或日期时间?
-
还显示您的工厂代码是如何制作的?
-
'first_name' => $faker->firstname, 'last_name' => $faker->lastname, 'email' => $faker->unique()->safeEmail, 'email_verified_at' = > $faker->randomElement([false , true]), 'mobile' => $faker->phoneNumber, 'mobile_verified_at' => $faker->randomElement([true , false]), 'password' => '$2 y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // 密码 'remember_token' => Str::random(10),
-
email_verified_at这里你需要传递一个日期,只需now()看看效果。 -
hx 为你的答案,我使用这一行 'email_verified_at' => $faker->dateTime 但我有一个新错误 >>>>>> Illuminate\Database\QueryException SQLSTATE[22003]: Numeric value超出范围:1264 第 1 行的“email_verified_at”列的值超出范围(SQL:插入用户(first_name、last_name、email、email_verified_at、mobile、mobile_verified_at、password、remember_token、updated_at、created_at)值(Julia、Lubowitz、 bfay@example.com, 1975