How to Resolve Errors in CakePHP After Changing Database Structure – Missing Fields Error

Being an avid CakePHP user, I had the idea that I could do some things and get the desired results in my application whenever I wanted.

Looking now I’ve learned something new again. I recently renamed some fields in one of the tables in my database. I also made the necessary changes to the model file (refactoring) for that table in order to avert any unexpected results in my application.

yahoo internal server error message

So I tested the application locally to ensure there were no glitches and then committed and pushed my changes to the live repository.

But to my utmost dismay – it broke! My application was no longer functioning in one part. Next thing that came to mind was to delete the files in the tmp/cache/models to be sure the table structure wasn’t cached.

Yet, no joy. Now I was thinking of going into the Cakephp core library to find out why this thing was still using an old cached copy of the database table.

Looking through the Model.php file I noticed the caching was still based on the files in the tmp directory which I had deleted.

Finally, I decided to take one more swipe at the tmp directory this time deleting the files in both the tmp/cache/models and tmp/cache/persistent directories.

Alas! All the errors were gone. Now I’ll always remember to delete the files here manually of write an addon to do just that after modifying my database structure.


Untraceable CakePHP Shell Error Solved At Last!

So after spending near 5 hours on Saturday looking for why my Cake Shell was not running on the online server, I finally figured it out.

The first road block I hit was with file permissions.

My web server was configured for write access to just the cache and logs folders inside of the /tmp folder. It turns out that the Cake shell needs to be able to write to the /tmp/cache/persistent. Also, the parent directory must be writeable. So I ended up changing the tmp folder with:

chmod 775 /srv/www/../app/tmp

Finally, the permissions error was gone, and then the next error came that got my searching for hours without respite.

I had written my shell app and tested it locally, ensuring I included all the needed database tables at the top of the class with: public $uses = array(…);

Everything should work now. Git push and let’s go… But no! Some new error message just right in my face.

Error: Database connection “Mysql” is missing, or could not be created.

The thing here was that I could not understand why I was getting a database error when my app was working online.

After so many hours searching on Stackoverflow, Bing, and Lighthouse I finally suspendied my frustration and decided to look at the servers logs.

Nothing in the logs made sense, I tried doing setsebool -P httpd_can_network_connect=1 to see if that would work, but that didn’t change a thing as SELINUX was already disabled.

Then I tried adding some lines with extensions config and socket path to the my.cnf file. That didn’t make any difference even after several reboots and service reloads.

Finally I remembered that I had dynamically set my connection in the database.php file used by CakePHP to choose either a default connection for localhost and a different one for the online server. Alas!!! That was it. Adding a condition after the dynamic selection fixed the problem in database.php

All I did was add this to the __construct method:

if (gethostname() == ‘Hostname‘){ //Find hostname using: $ hostname at your *nix shell
$this->default = $this->online;

Set debug to 2 in core.php to clear caches, and then changed it back to 0.

And that was the end of my shell nightmare.


Why Do We Have Left, Right, and Inner Joins in SQL?

English: This diagram is generated by "Re...

This is one of those blitz posts I occasionally write.

This post is meant for those who like to just skim through the loads of paperwork that often tends to be boring.

Here’s the drift straight up. You have LEFT JOIN, RIGHT JOIN, and INNER JOIN.

We use the LEFT JOIN most times because by default we seek the data from the table on the left side, (the table calling the join).


SELECT U.*, P.screen_name FROM users U LEFT JOIN profiles P ON ( WHERE = 2;

The users table is the one calling the join (on the left) in the above SQL query.


* Use LEFT joins when you want to return data in the left table whether or not there is a matching row in the right table. The above will return the user with id = 2 whether or not there is a profile record in the profiles table.


* Use RIGHT join when you want data from the RIGHT table whether or NOT there is a matching row in the LEFT table. With this RIGHT JOIN, even if there is no user with id =2 in the users table, and there is a row in the profiles table with user_id =2, we will get a result after the query containing the profile information at least.


The third most used join is the INNER JOIN, which is like strict mode, it’s all or nothing.

* Use INNER join when you want records from both tables in every case. The INNER join will return results only if there is a row in the users table that matches a row in the profile table, otherwise you will get no results if any of the tables does not have a corresponding row for the other side of the join either left or right.

There are other types of JOINS like the CROSS JOIN, and combinations of different JOINs like FULL OUTER JOIN…

You get the drift now.

You can see some more information about joins in this external article