发行
我试图让cakephp烘焙一个控制器,但出现了一个错误:

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

背景资料
我在apache、php和postgresql上使用lappstack
PostgreSQL 9.0.3数据库
菲律宾比索5.3
阿帕奇2
Cakephp 2.3.1版
我能做什么
我能烤一个模型。到目前为止,我已经为每个控制器创建了一个模型。
webapp运行良好。我从头开始构建模型、控制器和视图,一切正常。
使用pgadmin3和psql从web应用远程连接到db
完全cakephp烘焙错误
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}

配置文件: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',
);

主机曾经是外部IP地址,运行良好,但我将其更改为127.0.0.1,因为其他文章提到Bake Plays更适合127.0.0.1。
研究
我找到了两篇相关的stackoverflow文章,但它们似乎无法解决我的问题。
更改IP地址似乎没有帮助。
cake console 2.2.1: Bake errors
这使用的是一个sqlite数据库,它是一个实际的文件。我用的是postgresql,这行不通。
Bake tool cannot see tables in SQLite3 database

最佳答案

问题的最终结果是对表具有权限。如果在./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实用程序没有影响,但在尝试插入依赖于序列作为默认值的新记录时,可能会导致问题。

09-25 17:13