8

I have added a new column to the newsletter_subscriber table, 'artists_followed'. in my overridden Mage_Newsletter_Model_Subscriber model class, I have added the following function:

public function updateSubscriberArtists($email, $artist) {
    $this->loadByEmail($email);
    if ($this->getId()) {
        $this->setArtistsFollowed($artist);

        try {
            $this->save();
        }
        catch (Exception $e) {
            throw new Exception($e->getMessage());
        }
    }
}

everything runs ok, no errors are thrown, but when I look in the database, the new column is not populated.

My table is:

CREATE TABLE `mage_newsletter_subscriber` (
  `subscriber_id` int(7) unsigned NOT NULL AUTO_INCREMENT,
  `store_id` smallint(5) unsigned DEFAULT '0',
  `change_status_at` datetime DEFAULT NULL,
  `customer_id` int(11) unsigned NOT NULL DEFAULT '0',
  `subscriber_email` varchar(150) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL DEFAULT '',
  `subscriber_status` int(3) NOT NULL DEFAULT '0',
  `subscriber_confirm_code` varchar(32) DEFAULT 'NULL',
  `created_at` datetime DEFAULT NULL,
  `campaign_source` varchar(255) DEFAULT NULL,
  `artists_followed` text,
  PRIMARY KEY (`subscriber_id`),
  KEY `FK_SUBSCRIBER_CUSTOMER` (`customer_id`),
  KEY `FK_NEWSLETTER_SUBSCRIBER_STORE` (`store_id`),
  CONSTRAINT `FK_NEWSLETTER_SUBSCRIBER_STORE` FOREIGN KEY (`store_id`) REFERENCES `mage_core_store` (`store_id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Newsletter subscribers';

I'm racking my brain on this one. Any ideas? Am i missing something completely obvious?

2
  • I have the same issue. Added an attribute (column) in SalesRule, despite the model has that field correctly set, it never updates the database.
    – Vicary
    Dec 4, 2014 at 9:00
  • If someone uses n98-magerun, maybe this could help: ./n98-magerun cache:flush :) Nov 6, 2017 at 8:39

3 Answers 3

42

Another problem can be:

Zend_Db cached the structure of the database tables. If you add a new column, refresh the cache and Zend knows to fill the table.

Even if you have all cache disabled, the database structure and other info may still be cached.

Thanks james.c.funk

Make sure you delete everything in var/cache, this happens ,when you hit the button in the top but NOT when you check all checkboxes and refresh them!

10
  • do you mean the magento cache? or is there another cache that is zend-only?
    – Laura
    Feb 13, 2013 at 23:29
  • I have the same problem, but clearing the cache does not work for me.
    – Vicary
    Dec 4, 2014 at 8:54
  • 3
    Fixed the problem i was facing, only I needed to flush both Cache Storage and Magento Storage!
    – NathanielR
    Jun 23, 2015 at 7:35
  • 1
    Thnx @FabianBlechschmidt this was driving me crazy
    – BlueC
    Jun 13, 2016 at 13:45
  • 1
    Please stop thanking me in comments but instead upvote. We need the comment section for actual comments :-) Jun 13, 2016 at 14:18
2

ok, i got it to work by changing $this->setArtistsFollowed($artist) to $this->setData('artists_followed', $artist). i'm not sure why that worked though? what happened to the magic setter in this instance?

4
  • What does "echo typeof($this);" return?
    – philwinkle
    Feb 13, 2013 at 21:59
  • is that a magento-specific method? i'm getting Fatal error: Call to undefined function typeof() when i use that.
    – Laura
    Feb 13, 2013 at 23:31
  • 1
    Wow. My brain is fried on Javascript lol :) Sorry, try this: echo get_class($this);
    – philwinkle
    Feb 13, 2013 at 23:33
  • it's returning my overridden class. it's odd, i have another field that i added to this table, and using the magic setter works there, just not in this instance.
    – Laura
    Feb 14, 2013 at 17:23
1

You need to Flush Cache Storage.

You can do this through backend:

System -> Cache Management -> Click on 'Flush Cache Storage' button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.