Bake tool cannot see tables in SQLite3 database

随声附和 提交于 2019-12-21 16:59:44

问题


I am trying to build a simple app with CakePHP 2.1.1 using SQLite3 as the database. To save time I tried to use the bake tool to create a model for the following table:

CREATE TABLE animals (
  id integer primary key autoincrement,
  name text
);

but the bake tool returns the following error: Your database does not have any tables.

I figured Cake had a problem connecting to the database, so I went ahead and created the appropriate model, controller, and views myself. I inserted a single record into the animals table. And it worked.

I came up with nothing after searching the web. Either nobody tried to use the bake tool on an SQLite3 database, or I am having bad luck.

Does anyone have any ideas?

UPDATE

Here's the output of cake bake:

johan@ubuntu:~/php/app$ Console/cake bake model

Welcome to CakePHP v2.1.1 Console
---------------------------------------------------------------
App : app
Path: /home/johan/php/app/
---------------------------------------------------------------
---------------------------------------------------------------
Bake Model
Path: /home/johan/php/app/Model/
---------------------------------------------------------------
Your database does not have any tables.

and the config file:

<?php
class DATABASE_CONFIG {
    public $default = array(
        'datasource' => 'Database/Sqlite',
        'persistent' => false,
        'host' => 'localhost',
        'database' => 'cake',
    );
}

The database file is located at ~/php/app/webroot/cake


回答1:


Try putting a full path into your database config, this is what I did in my app:

<?php
define('DEFAULT_DB', TMP.'db'.DS.'main.db3');

class DATABASE_CONFIG {
    public $default = array(
        'datasource' => 'Database/Sqlite',
        'persistent' => false,
        'host' => '',
        'database' => DEFAULT_DB,
        'encoding' => 'utf8',
    );
}


来源:https://stackoverflow.com/questions/10370765/bake-tool-cannot-see-tables-in-sqlite3-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!