bake
bake copied to clipboard
Error on seed execution : Object of class DateTimeImmutable could not be converted to string
This is a :
-
[x] bug
-
CakePHP Version: 4.3.8.
-
Migrations plugin version: 3.5.1.
-
Bake plugin version (if relevant): 2.7.0.
-
Database server (MySQL, SQLite, Postgres): MariaDB 10.4.10
-
PHP Version: 7.4.0
-
Platform / OS: Bug appear on both Windows 11 / Wamp and Linux Debian with Apache2
Issue with seeds on a datetime field
When I execute the following command
bin/cake bake seed --data Groups
This error occurs :
2022-04-25 10:43:32 error: [Error] Object of class DateTimeImmutable could not be converted to string in D:\wamp64\www\ssk_dashboard\vendor\robmorgan\phinx\src\Phinx\Db\Adapter\PdoAdapter.php on line 335
Stack Trace:
- D:\wamp64\www\ssk_dashboard\vendor\robmorgan\phinx\src\Phinx\Db\Adapter\PdoAdapter.php:335
- D:\wamp64\www\ssk_dashboard\vendor\robmorgan\phinx\src\Phinx\Db\Adapter\AdapterWrapper.php:180
- D:\wamp64\www\ssk_dashboard\vendor\robmorgan\phinx\src\Phinx\Db\Adapter\TimedOutputAdapter.php:102
- D:\wamp64\www\ssk_dashboard\vendor\robmorgan\phinx\src\Phinx\Db\Adapter\AdapterWrapper.php:180
- D:\wamp64\www\ssk_dashboard\vendor\robmorgan\phinx\src\Phinx\Db\Table.php:652
- D:\wamp64\www\ssk_dashboard\vendor\robmorgan\phinx\src\Phinx\Db\Table.php:624
- D:\wamp64\www\ssk_dashboard\vendor\robmorgan\phinx\src\Phinx\Db\Table.php:682
- D:\wamp64\www\ssk_dashboard\config\Seeds\GroupsSeed.php:108
- D:\wamp64\www\ssk_dashboard\vendor\robmorgan\phinx\src\Phinx\Migration\Manager\Environment.php:146
- D:\wamp64\www\ssk_dashboard\vendor\robmorgan\phinx\src\Phinx\Migration\Manager.php:416
- D:\wamp64\www\ssk_dashboard\vendor\robmorgan\phinx\src\Phinx\Migration\Manager.php:557
- D:\wamp64\www\ssk_dashboard\vendor\robmorgan\phinx\src\Phinx\Console\Command\SeedRun.php:102
- D:\wamp64\www\ssk_dashboard\vendor\cakephp\migrations\src\Command\Phinx\CommandTrait.php:37
- D:\wamp64\www\ssk_dashboard\vendor\cakephp\migrations\src\Command\Phinx\Seed.php:76
- D:\wamp64\www\ssk_dashboard\vendor\symfony\console\Command\Command.php:298
- D:\wamp64\www\ssk_dashboard\vendor\symfony\console\Application.php:1015
- D:\wamp64\www\ssk_dashboard\vendor\symfony\console\Application.php:299
- D:\wamp64\www\ssk_dashboard\vendor\symfony\console\Application.php:171
- D:\wamp64\www\ssk_dashboard\vendor\cakephp\migrations\src\Command\MigrationsCommand.php:126
- D:\wamp64\www\ssk_dashboard\vendor\cakephp\cakephp\src\Console\BaseCommand.php:179
- D:\wamp64\www\ssk_dashboard\vendor\cakephp\migrations\src\Command\MigrationsCommand.php:198
- D:\wamp64\www\ssk_dashboard\vendor\cakephp\cakephp\src\Console\CommandRunner.php:334
- D:\wamp64\www\ssk_dashboard\vendor\cakephp\cakephp\src\Console\CommandRunner.php:172
- D:\wamp64\www\ssk_dashboard\bin\cake.php:12
Below my complete seed file content
<?php
declare(strict_types=1);
use Migrations\AbstractSeed;
/**
* Groups seed.
*/
class GroupsSeed extends AbstractSeed
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeds is available here:
* https://book.cakephp.org/phinx/0/en/seeding.html
*
* @return void
*/
public function run()
{
$data = [
[
'id' => 1,
'code' => 'SSKADMIN',
'libelle' => 'Administrateur SSK',
'url_dashboard' => NULL,
'createdAt' =>
Cake\I18n\FrozenTime::__set_state(array(
'date' => '2022-04-13 08:08:59.000000',
'timezone_type' => 3,
'timezone' => 'UTC',
)),
'modifiedAt' =>
Cake\I18n\FrozenTime::__set_state(array(
'date' => '2022-04-13 08:09:00.000000',
'timezone_type' => 3,
'timezone' => 'UTC',
)),
'deleted' => false,
],
[
'id' => 2,
'code' => 'CHEF_BASSIN',
'libelle' => 'Chef de bassin',
'url_dashboard' => NULL,
'createdAt' =>
Cake\I18n\FrozenTime::__set_state(array(
'date' => '2022-04-13 10:45:41.000000',
'timezone_type' => 3,
'timezone' => 'UTC',
)),
'modifiedAt' =>
Cake\I18n\FrozenTime::__set_state(array(
'date' => '2022-04-13 10:45:41.000000',
'timezone_type' => 3,
'timezone' => 'UTC',
)),
'deleted' => false,
],
[
'id' => 3,
'code' => 'RESPONSABLE_TECHNIQUE',
'libelle' => 'Responsable technique',
'url_dashboard' => NULL,
'createdAt' =>
Cake\I18n\FrozenTime::__set_state(array(
'date' => '2022-04-13 10:45:54.000000',
'timezone_type' => 3,
'timezone' => 'UTC',
)),
'modifiedAt' =>
Cake\I18n\FrozenTime::__set_state(array(
'date' => '2022-04-13 10:45:54.000000',
'timezone_type' => 3,
'timezone' => 'UTC',
)),
'deleted' => false,
],
[
'id' => 4,
'code' => 'UTILISATEUR',
'libelle' => 'Utilisateur standard',
'url_dashboard' => NULL,
'createdAt' =>
Cake\I18n\FrozenTime::__set_state(array(
'date' => '2022-04-13 10:46:08.000000',
'timezone_type' => 3,
'timezone' => 'UTC',
)),
'modifiedAt' =>
Cake\I18n\FrozenTime::__set_state(array(
'date' => '2022-04-13 10:46:08.000000',
'timezone_type' => 3,
'timezone' => 'UTC',
)),
'deleted' => false,
],
];
$table = $this->table('groups');
$table->insert($data)->save();
}
}
When I remove datetime columns, the seed runs successfully.