CodeIgniter Forums
Migrate users to shield - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Migrate users to shield (/showthread.php?tid=90131)



Migrate users to shield - frocco - 02-14-2024

Hello,

I am using migrations to insert users from another application to shield users table.
I need to preserve the previous id value and insert it as the current id.
shield will not allow me to replace the primary key id with current value.

I cannot get this to work.

Code:
$user = new User([
                "id" => $row->id, // Previous id from other database table
  ]);
$model = new UserModel;
            $model->save($user);

            $user = $model->findById($model->getInsertID());
            $user->activate();



RE: Migrate users to shield - kenjis - 02-14-2024

Do not use the Model. CodeIgniter Model dose not permit to change the id.

Use Query Builder.
https://codeigniter.com/user_guide/database/query_builder.html


RE: Migrate users to shield - frocco - 02-14-2024

Thanks, will try it.