We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Database Adapter not setting schemas in PostgreSQL


I'm having a problem with my micro application, I use PostgreSQL as database, but the database adapter I create don't set the schema for the models and I need to do it manually using the models manager, how can I avoid setting the schema manually for every model?

This is how I'm creating the Adapter

use Phalcon\Db\Adapter\Pdo\Postgresql as DbAdapter;

return new DbAdapter(array(
    "host" => $config->database->host,
    "username" => $config->database->username,
    "password" => $config->database->password,
    "dbname" => $config->database->dbname,
    "schema" => $config->database->schema,

This doesn't work

$person = new Person;
$person = $person->findFirst(1);

This works:

$person = new Person;
$app->modelsManager->setModelSchema($person, 'myschema');
$person = $person->findFirst(1);

If I don't set the schema manually then the model object can't find the tables:

Table "person" doesn't exist on database when dumping meta-data for Person.

I think the script is always reading the public schema instead of the one I set up.



I'm solving this issue setting the schema in the model initialize, which I don't think is necessary since Phalcon should do it automatically, I think is a bug that I'm going to report.

Here is the code that must be added in the model:

    public function initialize() {
        $this->getModelsManager()->setModelSchema($this, 'the_schema_name');


Any other idea?!!!

public function initialize()


public function getSchema()
    return 'the_schema_name';