1

I'm upgrading a system from CakePHP 1.1 to 1.3. When using create() (followed by save()) in 1.1 the system would happily add an insert an entry to the database with the created and modified datetime fields set to that of the time it was created. However, in 1.3 this is no longer correctly happening. Here the modified is still set to the current time upon the creation and save, but the created datetime is not being set. Any suggestions as to why this might be occurring? Thanks!

Create Table Code (as requested in comment):

CREATE TABLE `units` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `id_b36` VARCHAR(4) NULL DEFAULT NULL,
    `subject_id` INT(10) UNSIGNED NOT NULL,
    `gradelevel_id` INT(10) UNSIGNED NOT NULL,
    `user_id` INT(10) UNSIGNED NOT NULL,
    `school_id` INT(10) NULL DEFAULT NULL,
    `district_id` INT(10) NULL DEFAULT NULL,
    `description` VARCHAR(255) NOT NULL,
    `sort` FLOAT(5,1) NOT NULL DEFAULT '0.0',
    `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
    `modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
    PRIMARY KEY (`id`),
    INDEX `subject_id` (`subject_id`),
    INDEX `gradelevel_id` (`gradelevel_id`),
    INDEX `sort` (`sort`),
    INDEX `school_id` (`school_id`, `district_id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
AUTO_INCREMENT=483

I should note that this is just one of the tables, the same thing occurs on all other models. Thanks!

2
  • show the database create-table statement for the table with no created data please Commented Aug 23, 2013 at 15:15
  • @AD7six: Added to the question above. Commented Aug 23, 2013 at 15:48

1 Answer 1

2

created DEFAULT NULL

CakePHP will only populate created if it is defined as NULL:

By defining a created and/or modified field in your database table as datetime fields (default null), CakePHP will recognize those fields and populate them automatically whenever a record is created ...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.