Book Image

CakePHP 2 Application Cookbook

By : James Watts, Cake Software Foundation, Inc.
Book Image

CakePHP 2 Application Cookbook

By: James Watts, Cake Software Foundation, Inc.

Overview of this book

Table of Contents (20 chapters)
CakePHP 2 Application Cookbook
About the Authors
About the Reviewer

Schema handling

CakePHP is packed with a console shell for schema management, which gives you the ability to keep your database structure defined in a schema file in your version control system. This schema file keeps track of the changes made to your database and applies schema changes without touching your current data.

A schema file is a regular PHP file, located by convention in app/Config/Schema/schema.php. This file describes your database tables using properties as one property per table. Each property holds an array with all the columns in your table, their type, and other metadata required to fully describe the table.

Getting ready

You'll need to create at least one table in your database and its associated model. The shell schema processes models defined in your application, not the actual tables in your database.

So, create a profiles table in your database, using the following SQL statement:

CREATE TABLE profiles (
  title VARCHAR(100) NOT NULL,