创建数据库
创建一个用来存放Blog帖子的表格,并且初始化一些数据。以下是SQL语句:
CREATE TABLE posts (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(50),
body TEXT,
created DATETIME DEFAULT NULL,
updated DATETIME DEFAULT NULL
);
INSERT INTO posts (title,body,created)
VALUES ('The title', 'This is the post body.', NOW());
INSERT INTO posts (title,body,created)
VALUES ('A title once again', 'And the post body follows.', NOW());
INSERT INTO posts (title,body,created)
VALUES ('Title strikes back', 'This is really exciting! Not.', NOW());
注意表名称是复数形式, 这是Cake使用的所有表格的默认形式。还有,id、created、updated字段是有特殊含义的,等一会儿你就会发现。也就是说现在你不应该更改他们的名字。