Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bake tool cannot see tables in SQLite3 database

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

like image 519
Johan A. Avatar asked Apr 29 '12 08:04

Johan A.


People also ask

How do I view tables in SQLite?

If you are running the sqlite3 command-line access program you can type ". tables" to get a list of all tables. Or you can type ". schema" to see the complete database schema including all tables and indices.

Where does SQLite store data?

The Android SDK provides dedicated APIs that allow developers to use SQLite databases in their applications. The SQLite files are generally stored on the internal storage under /data/data/<packageName>/databases.


1 Answers

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',
    );
}
like image 132
dr Hannibal Lecter Avatar answered Sep 28 '22 16:09

dr Hannibal Lecter