Reputation: 851
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.
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}
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.
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
Upvotes: 3
Views: 2959
Reputation: 851
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.
Upvotes: 2