Magento model won't save values

10,683

Solution 1

Disabling the caching options in Magento's Admin system does NOT disable all caching. Magento still caches table structures, locale data, etc., in the var/cache/ directory, under Magento's root folder (this is NOT /var/cache).

To disable all caching, add the following <cache> entry to the <global> section of app/etc/local.xml:

<config>
    <global>
        ...
        <cache>
            <backend>Zend_Cache_Backend_BlackHole</backend>
        </cache>
        ...

To flush the cache containing the table structures, go into the Admin system, and select System > Cache Management > Flush Cache Storage (not Flush Magento Cache!). This will remove the files in var/cache.

You can also flush the cache via the command line:

$ sudo rm -fr /path/to/your/magento/installation/var/cache/*

Solution 2

as far as I know - Magento caching database structure somehow. so just Flush Magento Cache should help

Share:
10,683
Christoffer Bubach
Author by

Christoffer Bubach

Updated on June 04, 2022

Comments

  • Christoffer Bubach
    Christoffer Bubach almost 2 years

    I'm working on a backend module that saves to a custom table. My problem is that I've added fields to this table as I've been working on it, the newly added fields won't save with the model ->Save() function.

    I've completely removed the module and resinstalled it, letting it create my custom table from scratch in case it had some internal field count that I wasn't aware of, but still same result.

    After adding my data I do a var dump on what gets submitted like this:

    $model = Mage::getModel("smsmanager/sms")->addData($post_data)->save();
    var_dump($model->getData()); exit;
    

    With the result

    array
      'form_key' => string 'RUGN3fruWobAf8CZ' (length=16)
      'message' => string 'adg asdg sad' (length=14)
      'country' => string 'SE' (length=2)
      'telephone' => string '+46707332290' (length=12)
      'type' => int 2
      'id' => string '5' (length=1)
    

    And everything looks just fine. When I check the newly created row with ID 5, I get this:

    |-----------------------------------------------------------------------------------------------------------|
    |id int(11)| type int(11) | telephone varchar(20) | country varchar(2) | message text | date timestamp      |
    |-----------------------------------------------------------------------------------------------------------|
    | 5        | 2            | +46707332290          | NULL               | adg asdg sad | 2013-03-19 21:44:51 |
    |-----------------------------------------------------------------------------------------------------------|
    

    I've also tried to manually insert other fields into the database table like "junkfield" and add it with $post_data['junkfield'] = "hello"; and it also gets null as value.

    For me, it's looking like Magento is screwing with me. Defying logic. Anybody got another take on what could be wrong? Oh and before I forget, here's my table layout:

    CREATE TABLE IF NOT EXISTS `sms_entry` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `type` int(11) NOT NULL,
      `telephone` varchar(20) DEFAULT NULL,
      `country` varchar(2) DEFAULT NULL,
      `message` text,
      `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
    

    No matter what I try it just won't save the country code. I also tried making teh varchar larger then 2, switching name to country_code (incase country was reserved or something). Nothing seems to help.

  • Christoffer Bubach
    Christoffer Bubach about 11 years
    But I removed everything, including the core_resources row with the module and then re-installed it. Also all my cache settings are turned off for this local dev-machine.
  • TaganPablo
    TaganPablo about 11 years
    I had same issues sometime ago and all my caches were disabled too. And as I remember "Flush cache" was my solution.
  • Christoffer Bubach
    Christoffer Bubach about 11 years
    Hmm, that would explain a lot. I spent like 2 hours with this and was beginning to think that I was loosing my mind. :P
  • Ross Smith II
    Ross Smith II about 11 years
    Unfortunately, this answer is not correct. [Flush Magento Cache] doesn't remove the table structure cache files in var/cache, only the [Flush Cache Storage] option does that.
  • TaganPablo
    TaganPablo about 11 years
    Many thanks! Actually my answer was based only on my memories and as far as I remember - Flush Cache helped me.
  • nakajuice
    nakajuice almost 9 years
    wow thanks! now i get why magento cached my errors that i fixed