11

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.

3 Answers 3

34

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/*
2
  • 1
    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 Commented Mar 20, 2013 at 2:44
  • wow thanks! now i get why magento cached my errors that i fixed
    – nakajuice
    Commented Jul 1, 2015 at 0:17
6

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

4
  • 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. Commented Mar 19, 2013 at 22:11
  • 1
    I had same issues sometime ago and all my caches were disabled too. And as I remember "Flush cache" was my solution.
    – TaganPablo
    Commented Mar 19, 2013 at 22:44
  • 2
    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. Commented Mar 21, 2013 at 18:17
  • Many thanks! Actually my answer was based only on my memories and as far as I remember - Flush Cache helped me.
    – TaganPablo
    Commented Mar 25, 2013 at 20:13
0

+1 note also that in my case, I just forgot I was using REDIS cache, so in case you use this, don't forget to remove this cache too!!

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.