Cakephp 1.3.14 not loading database schema

We recently made some changes to our site to prepare it for pre-production:

  • Moved to a load-balanced architecture
  • Now use memcache/memcached to maintain session data
  • Enabled APC

Now, everything was working until we made some change that we cannot recall that has caused the database to not load schema properly. Here is an output of some debug:

    Warning (512): SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 684]

    Query: SHOW FULL COLUMNS FROM

    Warning (2): Invalid argument supplied for foreach() [APP/models/datasources/dbo/dbo_mysql.php, line 127]

    Warning (2): array_keys() expects parameter 1 to be array, boolean given [CORE/cake/libs/model/datasources/dbo_source.php, line 1968]

    Notice (8): Trying to get property of non-object [CORE/cake/libs/model/datasources/dbo_source.php, line 812]

    Query: SHOW FULL COLUMNS FROM

    Query: SHOW FULL COLUMNS FROM

    Query: SHOW FULL COLUMNS FROM

    Query: SHOW FULL COLUMNS FROM

    Query: SHOW FULL COLUMNS FROM

    Query: SHOW FULL COLUMNS FROM 

As you can see, it is not loading the table names.

The other problem we noticed, is that when the query is generated, it is generated like this:

SELECT Project.id FROM AS Project WHERE 1=1

Notice that there is no table name, it simply tries to create the alias on a blank table name.

Any thoughts?

Answers


We recently made some changes to our site to prepare it for pre-production:

Thankfully you version-control your code changes and can simply roll back until you find a working version and compare to find the breaking change. With git this is easily done using git bisect.

No? Well..

Debug and identify the cause

As with any error - step one should be to look at where the error is coming from:

// cake/models/datasources/dbo/dbo_mysql.php
$cols = $this->query('SHOW FULL COLUMNS FROM ' . $this->fullTableName($model));

foreach ($cols as $column) { // #127

What should be clear here, is that Cake is unable to determine the full table name for your model.

You're trying to query a model with no table

Looking at the source for fullTableName:

// cake/libs/model/datasources/dbo_source.php
function fullTableName($model, $quote = true) {
        if (is_object($model)) {
                $table = $model->tablePrefix . $model->table;
        } elseif (isset($this->config['prefix'])) {
                $table = $this->config['prefix'] . strval($model);
        } else {
                $table = strval($model);
        }
        if ($quote) {
                return $this->name($table);
        }
        return $table;
}

It should be clear that the model has no table according to cake.

Common causes:

  • The model property useTable is set to false
  • No describe permissions

Given the info in the question - it's most likely the first is the reason.


Need Your Help

Open TFS document directly in Word from Visual Studio

visual-studio-2013 tfs ms-office

Our project documents are currently maintained using TFS. Visual Studio (2013) allows me to view all the checked in documents through the Team Explorer window, under Documents.

Windows Phone - Using ContextMenu for Images in a WrapPanel

wpf silverlight windows-phone-8

I have a wrap panel that is populated with Image controls at run time. I want to use a context menu to remove images I want to delete.