Creating new file folders in SS4.2.1 with PostgreSQL (pg_connect)

Silverstripe Version:



Is anyone else having difficulty running Silverstripe 4.2.1 with PostgreSQL 10.0? When I try to add a folder under Files in the CMS admin, I receive this 500 error:

ERROR [Emergency]: Uncaught SilverStripe\ORM\Connect\DatabaseException: Couldn’t run query:

SELECT DISTINCT “Group”.“ClassName”, “Group”.“LastEdited”, “Group”.“Created”, “Group”.“Title”, “Group”.“Description”, “Group”.“Code”, “Group”.“Locked”, “Group”.“Sort”, “Group”.“HtmlEditorConfig”, “Group”.“ParentID”, “Group”.“ID”,
CASE WHEN “Group”.“ClassName” IS NOT NULL THEN “Group”.“ClassName”
ELSE E’SilverStripe\Security\Group’ END AS “RecordClassName”

FROM “Group”

WHERE (“Group”.“ID” = $1)


ERROR: invalid input syntax for integer: “unchanged”
IN GET /admin/assets/schema/folderCreateForm/0
Line 64 in /var/www/html/html/vendor/silverstripe/framework/src/ORM/Connect/DBConnector.php

I tried a fresh install. I also tried a fresh install using MySQL instead, and everything works as expected. I’m guessing there’s some kind of escaping issue somewhere.

1 Like

Did you find the answer?
I have the same thing :confused:

Just noticed this. Yes, there was a fix added to 4.3.2:

In SilverStripe 4, you can create new file folders using the Folder class. To create a new file folder, you will need to do the following:

Connect to your PostgreSQL database and open a new PHP file.
Import the necessary classes at the top of your PHP file:
use SilverStripe\Assets\Folder;
use SilverStripe\ORM\DataObject;

Create a new Folder object and set its properties:

$folder = new Folder();
$folder->Name = 'My Folder';
$folder->ParentID = 0; // set the parent folder ID
$folder->write(); // save the folder to the database

To create a subfolder within an existing folder, you will need to set the ParentID property to the ID of the parent folder. You can retrieve the ID of a folder using the ID property of the Folder object.

$parentFolder = Folder::get()->byID(1); // get the parent folder with ID 1
$subfolder = new Folder();
$subfolder->Name = 'My Subfolder';
$subfolder->ParentID = $parentFolder->ID;

If you want to create multiple folders at the same time, you can use the Folder::batch_create() method. This method allows you to create multiple folders in a single database transaction, which can be more efficient than creating folders one at a time.

$folders = [    ['Name' => 'Folder 1'],
    ['Name' => 'Folder 2'],
    ['Name' => 'Folder 3'],