We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Table "robots" doesn't exist on database when dumping meta-data

Hi guys, I am a very beginner with phalcon, I started just few days ago.

I found this problem on Phalcon Documentation 1.3.0 - Tutorial 3: Creating a Simple REST API (pdf format)

When I invoke /api/robots via Browser I receive the following exception

Table "robots" doesn't exist on database when dumping meta-data

By Googling around the web I found the fix. Here you are

1) Go on Robots.php file 2) Just before the function validation() add the following snippet

    **public function getSource(){
            return 'Robots';
    }**

Maybe it could be useful add that to the official documentation. Furthemore I kindly suggest to attach the database definition to the tutorial. This is the mine one

    **drop database if exists restapi;
    create database restapi;
    use restapi;
    create table Robots (
        `id` int(11) not null auto_increment,
        `name` varchar(100) not null default '',
        `type` varchar(100) not null default '',
        `year` int(11) unsigned not null,
        primary key(`id`)
    );

insert into Robots (name, type, year) values ('Terminator','mechanical','1980'),('Robocop','mechanical','1992'),('Astro Boy','virtual','1986'),('Cyborg','droid','1975');

I hope this helps.

The documentation does state how a model and database table should be related, here: https://docs.phalcon.io/en/latest/reference/models.html#creating-models

I am new using phalcon but i really like it. I had this same issue and found that the way to solve it is to use the getResource ovlerload function in your model but i didnĀ“t find the right explanation to do this. After spending some time in this issue i realized that, in linux, because it is case sensitive, the model is no able to match the query result to the model when executing a query. So, the way to solve it is to use the get source method putting the name in the return in the same case it was used to create the database.

I got the same error when on multi modules system through following commands : phalcon create-all-models --get-set --mapcolumn --directory apps\frontend\models In controller file along with this I got the error: $ForexRates = ForexRates::find(); print_r($ForexRates);

Got the error: Notice: Array to string conversion in C:\xampp\htdocs\testingtoday\apps\frontend\Module.php on line 78 Notice: Array to string conversion in C:\xampp\htdocs\testingtoday\apps\frontend\Module.php on line 78 Table 'forex_rates' doesn't exist in database when dumping meta-data for testingtoday\frontend\Models\ForexRates

And on following line changed the code : in testingtoday\apps\frontend Module.php

$di['db'] = function () use ($config) { // return new DbAdapter($config->toArray()); //}; To Replaces with : $di['db'] = function() use ($config) { // return new DbAdapter(array( "host" =>$config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname )); };

Just wanted to leave a comment here that I was getting this error too. And it was because I had a database field called source and a setter setSource() which conflicts with phalcons variables and functions. Renamed source database field and everything is fine!