Cakephp Bake - 在数据源中找不到表

时间:2013-06-17 19:44:36

标签: php postgresql cakephp controller cakephp-2.0

问题

我正在尝试让Cakephp烘烤一个控制器,我收到了一个错误:

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

背景资料

  • 我正在使用Lappstack进行Apache,PHP和Postgresql
  • Postgresql 9.0.3数据库
  • PHP 5.3
  • Apache 2
  • Cakephp 2.3.1

我能做什么

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

Full Cakephp Bake错误

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地址似乎没有帮助。 cake console 2.2.1: Bake errors

这是使用sqlite数据库,它是一个实际的文件。我正在使用postgresql,这将无法正常工作。 Bake tool cannot see tables in SQLite3 database

1 个答案:

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