3
votes

Issue

I'm trying to get Cakephp to bake a controller, and I'm given an error:

Error: Table core_tablets for model CoreTablet was not found in datasource dev.

Background Information

  • I'm using Lappstack for my Apache, PHP, and Postgresql
  • Postgresql 9.0.3 database
  • PHP 5.3
  • Apache 2
  • Cakephp 2.3.1

What I am able to do

  • I am able to bake a model. I've created a model for each of the controllers so far.
  • The webapp works fine. I've built Models, Controllers, and Views from scratch and everything works.
  • Connect to DB from web app, remotely using pgadmin3, and psql

Full Cakephp Bake error

Enter a number from the list above,
type in the name of another controller, or 'q' to exit
[q] > CoreTablets
---------------------------------------------------------------
Baking CoreTabletsController
---------------------------------------------------------------
Would you like to build your controller interactively? (y/n)
[y] > n
Would you like to create some basic class methods
(index(), add(), view(), edit())? (y/n)
[n] > y
Would you like to create the basic class methods for admin routing? (y/n)
[n] >
Error: Table core_tablets for model CoreTablet was not found in datasource dev.
#0 /home/myusername/lappstack-1.2-5/apache2/htdocs/cpm_v2_dev/lib/Cake/Model/Model.php(3231): Model->setSource('core_tablets')
#1 /home/myusername/lappstack-1.2-5/apache2/htdocs/cpm_v2_dev/lib/Cake/Model/Model.php(1319): Model->getDataSource()
#2 /home/myusername/lappstack-1.2-5/apache2/htdocs/cpm_v2_dev/lib/Cake/Model/Model.php(1402): Model->schema()
#3 /home/myusername/lappstack-1.2-5/apache2/htdocs/cpm_v2_dev/lib/Cake/Model/Model.php(1390): Model->hasField('title', false)
#4 /home/myusername/lappstack-1.2-5/apache2/htdocs/cpm_v2_dev/lib/Cake/Model/Model.php(879): Model->hasField(Array)
#5 /home/myusername/lappstack-1.2-5/apache2/htdocs/cpm_v2_dev/lib/Cake/Console/Command/Task/ControllerTask.php(301): Model->__get('displayField')
#6 /home/myusername/lappstack-1.2-5/apache2/htdocs/cpm_v2_dev/lib/Cake/Console/Command/Task/ControllerTask.php(189): ControllerTask->bakeActions('CoreTablets', NULL, true)
#7 /home/myusername/lappstack-1.2-5/apache2/htdocs/cpm_v2_dev/lib/Cake/Console/Command/Task/ControllerTask.php(62): ControllerTask->_interactive()
#8 /home/myusername/lappstack-1.2-5/apache2/htdocs/cpm_v2_dev/lib/Cake/Console/Command/BakeShell.php(114): ControllerTask->execute()
#9 /home/myusername/lappstack-1.2-5/apache2/htdocs/cpm_v2_dev/lib/Cake/Console/Shell.php(392): BakeShell->main()
#10 /home/myusername/lappstack-1.2-5/apache2/htdocs/cpm_v2_dev/lib/Cake/Console/ShellDispatcher.php(200): Shell->runCommand(NULL, Array)
#11 /home/myusername/lappstack-1.2-5/apache2/htdocs/cpm_v2_dev/lib/Cake/Console/ShellDispatcher.php(68): ShellDispatcher->dispatch()
#12 /home/myusername/lappstack-1.2-5/apache2/htdocs/cpm_v2_dev/app/Console/cake.php(37): ShellDispatcher::run(Array)
#13 {main}

Config file: app/config/database.php

public $default = array(
    'datasource' => 'Database/Postgres',
    'persistent' => false,
    'host' => '127.0.0.1',
            'port' => '5433',
    'login' => 'notrealusername',
    'password' => 'notrealpassword',
    'database' => 'notrealdatabase',
    'prefix' => '',
            'schema' => 'notrealschema',
    //'encoding' => 'utf8',
);

public $dev = array(
    'datasource' => 'Database/Postgres',
    'persistent' => false,
    'host' => '127.0.0.1',
            'port' => '5433',
    'login' => 'notrealusername',
    'password' => 'notrealpassword',
    'database' => 'notrealdatabase',
        'prefix' => '',
            'schema' => 'notrealschema',
    //'encoding' => 'utf8',
);

The host used to be the external IP address, which worked fine but I changed it to 127.0.0.1 since other articles have mentioned bake plays nicer with 127.0.0.1.

Research

I've found two related Stackoverflow articles, but they don't seem to solve my issue.

Changing the IP address didn't seem to help. cake console 2.2.1: Bake errors

This is using a sqlite database which is an actual file. I'm using postgresql and this won't work. Bake tool cannot see tables in SQLite3 database

1
Did you create the table "core_tablets" in the database first before baking?jimiyash
Yes, every table was created in the database before baking. I was getting an error when baking the models. It was saying that the table could not be found.Tim Sanders
Is it spelled correctly? What models do you see when you do cake bake then choose model by typing M from the selection list.styks
@Kelvin Yes, the table is spelled correctly. When I do ./cake bake and choose M I receiving a listing of all Models currently in /app/ModelTim Sanders
Is dev datasource and default datasource the same database? Could it be possible the table may be present in the default DB and not the dev DB?styks

1 Answers

2
votes

The issue ending up being with permissions on the table. ./cake bake can't see the database if the user defined in app/config/database.php does not have permissions on the tables. All I needed to do was add permissions on the tables. This is what I did in my Postgresql database:

GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE my_schema.my_table TO notrealusername

I also add permission to the sequences used by the tables:

GRANT USAGE ON SEQUENCE my_schema.my_table TO notrealusername

The SQL is for Postgresql 9.1

Adding the permission to the sequences didn't make a difference for using the Bake utility, but it would have caused problems down the road when trying to insert new records that depend on a sequence for a default value.