CakePHP bake: SQLSTATE[42S02]: Base table or view not found

|
| By Webner

While running cake bake command for cakephp 3.0 we got the following error:

SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘tablename .columnname’ doesn’t exist

The culprit was a column with name test_id in one of the tables. As per bake command’s conventions about foreign keys, it says that:

If we have any foreign key column from table1 into table2, the column name should be table1_id.

“id” word after table1 has critical role here because if any field in table contains this suffix, Cake bake will treat it as foreign key and try to bake the code according to it.

In our case it Cake bake thought test_id is a foreign key (while it is not, it is just a regular field for us) and it started to look for a table with name test which never existed in our database. This is the reason problem occurred in our case.

After changing column name and removing suffix => id from the table, we baked the command again and it worked perfectly.

Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need Web development or any other software development assistance please contact us at webdevelopment@webners.com

Leave a Reply

Your email address will not be published. Required fields are marked *