phpmysqlcakephpcakephp-1.3

A specific column is not being inserted when saving a record


I am working with CakePHP 1.3.13. Here I have writen a code to insert form in to database.

Here, deals database table looks like below.

enter image description here

When I insert record into database so voucher_code column is not inserted.

Here when I print $this->data then it will gives all data like :

Array
(
[Deal] => Array
    (
        [title] => Deal title
        [original_price] => 350
        [discount] => 45
        [total_price] => 192.5
        [voucher_code] => TEST3211
        [redeem_points] => 158
        [deal_details] => tetert
        [condition] => Testing
        [deal_address] => tertre
        [deal_end_date] => 2016-05-26
        [no_of_deals] => 10
        [merchant_id] => 24
        [image] => 146399768856085.jpg
    )

)

Here I have write insert query like :

 $this->Deal->create();
 $this->Deal->save($this->data);

So all column's are inserted except voucher_code. So what will be the error ? and How can I resolve this error?


Solution

  • Only those columns/fields will be saved that are present in the cached database table schema, so when adding fields after CakePHP has already cached it, you'll have to clear the cache (delete app/tmp/cache/models) in order for the new columns to be recognized.