Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Error with Table 'x' don't exist in database when dumping meta-data for x

Hello !

I've been getting this error for some time and after strolling through Internet and this forum, I still can't seem to find any working solution.

So my system is:

  • Apache2/PHP7.1.6 server on an Arch linux computer.
  • PostgreSQL 9.6.

I made the 'user' table under the schema 'notepad' in the database 'postgres'.
Its structure is

CREATE TABLE notepad.user (
  uid SERIAL PRIMARY KEY,
  username VARCHAR(60) NOT NULL,
  -- subject to changes (Unclear on how to store the e-mail and password yet (about length)...
  email VARCHAR(512) NOT NULL,
  passwd VARCHAR(512) NOT NULL,
  -- signed 2_byte integer, to store the login_method
  -- https://www.postgresql.org/docs/8.1/static/datatype.html
  login_method SMALLINT NOT NULL
);

My loader is registering the models dir.

My User class is stored under $APP_PATH/models/User.php and is structured as following:

<?php
use Phalcon\Mvc\Model;

/**
 * Class User
 * Automatically maps to the table 'user'
 */
class User extends Model {
}

The table contains a few valid entries that can be accessed using a classical SQL request like SELECT * FROM notepad.user;
On the controller part, I'm requesting data by simply using $users = User::find();.

What I've tried

Making a custom getSource function

Following the answer here.

I did this code below and it didn't work (same error, error shown at the bottom of the subject).

<?php
use Phalcon\Mvc\Model;

/**
 * Class User
 * Automatically maps to the table 'user'
 */
class User extends Model {
    public function getSource() { return "user"; }
}

Setting the source manually

Following the guide here.

I did this code below and it didn't work (same error, error shown at the bottom of the subject).

<?php
use Phalcon\Mvc\Model;

/**
 * Class User
 * Automatically maps to the table 'user'
 */
class User extends Model {
    public function initialize() { $this->setSource('user'); }
}

Specifying the columns of the table as public properties in the model

Following the guide here.

I did this code below and it didn't work (same error, error shown at the bottom of the subject).
I kept the exact same column names.

<?php
use Phalcon\Mvc\Model;

/**
 * Class User
 * Automatically maps to the table 'user'
 */
class User extends Model {
    public $uid;
    public $username;
    public $email;
    public $passwd;
    public $login_method;
}

Upgrading the privileges of the database user used

I did a dedicated user for the project, called notepad and gave him full privileges over the schema notepad, but even with the root user postgres (nopasswd), it didn't work.

Error I'm getting (full error /w stack-trace)

Table 'user' doesn't exist in database when dumping meta-data for User

#0 [internal function]: Phalcon\Mvc\Model\MetaData\Strategy\Introspection->getMetaData(Object(User), Object(Phalcon\Di\FactoryDefault))
#1 [internal function]: Phalcon\Mvc\Model\MetaData->_initialize(Object(User), 'user-user', 'user', '')
#2 [internal function]: Phalcon\Mvc\Model\MetaData->readMetaDataIndex(Object(User), 0)
#3 [internal function]: Phalcon\Mvc\Model\MetaData->getAttributes(Object(User))
#4 [internal function]: Phalcon\Mvc\Model\Query->_executeSelect(Array, NULL, NULL)
#5 [internal function]: Phalcon\Mvc\Model\Query->execute()
#6 /srv/http/notepad/app/controllers/ShowcaseController.php(16): Phalcon\Mvc\Model::find()
#7 [internal function]: ShowcaseController->testAction()
#8 [internal function]: Phalcon\Dispatcher->callActionMethod(Object(ShowcaseController), 'testAction', Array)
#9 [internal function]: Phalcon\Dispatcher->_dispatch()
#10 [internal function]: Phalcon\Dispatcher->dispatch()
#11 /srv/http/notepad/public/index.php(45): Phalcon\Mvc\Application->handle()
#12 {main}

Output I'm getting with $this->db->query(&#039;SELECT username FROM notepad.user&#039;)->fetchAll();

[
    {"username":"Artemis","0":"Artemis"},
    {"username":"Neko","0":"Neko"},
    {"username":"Test","0":"Test"}
]

Thanks for reading this huge text and thanks in advance for any help given!

Thanks for the heads-up, I didn't know it was related to a database problem.

My code now looks like that:

File models/AbstractModel.php

<?php

use Phalcon\Mvc\Model;

class AbstractModel extends Model
{
    public function initialize()
    {
        $this->getModelsManager()->setModelSchema($this, DB_SCHEMA);
    }
}

File models/User.php

<?php

class User extends AbstractModel {}