我正在尝试让Cakephp烘烤一个控制器,我收到了一个错误:
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',
);
主机曾经是外部IP地址,工作正常,但我将其更改为127.0.0.1,因为其他文章提到烘焙效果更好127.0.0.1。
我发现了两篇相关的Stackoverflow文章,但它们似乎没有解决我的问题。
更改IP地址似乎没有帮助。 cake console 2.2.1: Bake errors
这是使用sqlite数据库,它是一个实际的文件。我正在使用postgresql,这将无法正常工作。 Bake tool cannot see tables in SQLite3 database
答案 0 :(得分:2)
问题最终是对表的权限。如果./cake bake
中定义的用户没有对表的权限,则app/config/database.php
无法查看数据库。我需要做的就是在表上添加权限。这就是我在Postgresql数据库中所做的:
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE my_schema.my_table TO notrealusername
我还添加了表格使用的序列的权限:
GRANT USAGE ON SEQUENCE my_schema.my_table TO notrealusername
SQL
适用于Postgresql 9.1
为序列添加权限对使用Bake实用程序没有任何影响,但在尝试插入依赖于默认值序列的新记录时,它会引起问题。