3

问题

我正在尝试让 Cakephp 烘焙控制器,但出现错误:

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

背景资料

  • 我正在为我的 Apache、PHP 和 Postgresql 使用 Lappstack
  • Postgresql 9.0.3 数据库
  • PHP 5.3
  • 阿帕奇 2
  • 蛋糕PHP 2.3.1

我能做什么

  • 我可以烤模型。到目前为止,我已经为每个控制器创建了一个模型。
  • 网络应用程序工作正常。我从头开始构建了模型、控制器和视图,一切正常。
  • 从 Web 应用程序连接到数据库,使用 pgadmin3 和 psql 远程连接

完整的 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,因为其他文章提到烘焙与 127.0.0.1 配合得更好。

研究

我找到了两篇相关的 Stackoverflow 文章,但它们似乎并没有解决我的问题。

更改 IP 地址似乎没有帮助。 蛋糕控制台 2.2.1:烘焙错误

这是使用一个实际文件的 sqlite 数据库。我正在使用 postgresql,这不起作用。 烘焙工具看不到 SQLite3 数据库中的表

4

1 回答 1

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 实用程序没有影响,但在尝试插入依赖于默认值序列的新记录时,会导致问题。

于 2013-07-10T19:15:16.353 回答