Asked thg 8 23, 2022 7:39 SA 61 0 1
  • 61 0 1
0

Cake migrations seed: [Error] Object of class DateTimeImmutable could not be converted to string in /var/www/html/cake_myapp/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php on line 335

Share
  • 61 0 1

Em sử dụng cake bake seed --data Users tạo được file "Seeds/UsersSeep.php" có đoạn data :

$data = $data = [
            [
                'id' => 1,
                'username' => 'pitocmsssss',
                'email' => 'demo123@admin.com',
                'amount' => 0,
                'created' => 
                Cake\I18n\FrozenTime::__set_state(array(
                'date' => '2020-04-01 07:14:22.000000',
                'timezone_type' => 3,
                'timezone' => 'UTC',
                )),
                'modified' => 
                Cake\I18n\FrozenTime::__set_state(array(
                'date' => '2022-08-22 04:03:58.000000',
                'timezone_type' => 3,
                'timezone' => 'UTC',
                )),
            ],...
  ]

Khi sử dụng cake migrations seed xuất hiện lỗi

Screen Shot 2022-08-23 at 14.31.21.png

Làm thế nào để fix ạ?

Thanks.

1 ANSWERS


Answered thg 8 23, 2022 8:11 SA
Accepted
0

Theo như nội dung trong file log thì vấn đề có vẻ là do bạn đã truyền một object của class DateTimeImmutable vào, trong khi expect của Cake lại là String.

ở đoạn này

'created' => Cake\I18n\FrozenTime::__set_state(array(
                'date' => '2020-04-01 07:14:22.000000',
                'timezone_type' => 3,
                'timezone' => 'UTC',
                )),

thay vì dùng Object, bạn thử dùng String không thôi xem sao

'created' => '2020-04-01 07:14:22',

Tương tự với phần modified.

Share
Avatar TMH @hoang55dd
thg 8 23, 2022 9:28 SA

Lỗi này em sửa như trên được rồi. Nhưng có cách nào khác không ạ tại đoạn này tạo bằng command nên nếu có nhiều bản ghi thì làm sao ạ?

0
| Reply
Share
Viblo
Let's register a Viblo Account to get more interesting posts.