# ActiveRecord migration failing to save

**URL:** <https://www.ruby-forum.com/t/activerecord-migration-failing-to-save/124768>\
**Category:** Rails\
**Created:** [January 2, 2008, 12:35pm UTC](https://www.ruby-forum.com/t/activerecord-migration-failing-to-save/124768 "2008-01-02T12:35:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![printmkr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9f8e36/32.png) [@printmkr](https://www.ruby-forum.com/u/printmkr)\
**Post date:** [January 2, 2008, 12:35pm UTC](https://www.ruby-forum.com/t/activerecord-migration-failing-to-save/124768/1 "2008-01-02T12:35:05Z")

</div>

Hi all,

I have a fairly simple migration below.  
All looks good to me and throws no errors but the d/b is not getting the  
new values. The final print cmd prints out the correct data. Any clues  
please ?

```
   web_referrers = WebReferrer.find :all

   web_referrers.each do |web_referrer|
     print web_referrer.ID,"\n"
     print web_referrer.ip_addresses,"\n"

     web_referrer.ip_addresses += ',203.190.235.96/27'
     web_referrer.ip_addresses.slice!('202.177.212.144/28')
     web_referrer.ip_addresses.sub!(/, *,/, ',')

     web_referrer.ip_addresses = tempIp
     print web_referrer.ip_addresses, "\n"
     web_referrer.save!
     print "Saved ", web_referrer.ID, "\n"
   end
```

---

<div class="post-metadata">

**Author:** ![printmkr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9f8e36/32.png) [@printmkr](https://www.ruby-forum.com/u/printmkr)\
**Post date:** [January 2, 2008, 12:36pm UTC](https://www.ruby-forum.com/t/activerecord-migration-failing-to-save/124768/2 "2008-01-02T12:36:34Z")

</div>

Sorry,

I have been playing with solutions.  
I should have deleted the line

> ```
> web_referrer.ip_addresses = tempIp
> 
> ```

Regards,  
Bill

Bill Comer wrote:

> Hi all,
> 
> I have a fairly simple migration below.  
> All looks good to me and throws no errors but the d/b is not getting the  
> new values. The final print cmd prints out the correct data. Any clues  
> please ?
> 
> ```
> web_referrers = WebReferrer.find :all
> 
> web_referrers.each do |web_referrer|
> print web_referrer.ID,"\n"
> print web_referrer.ip_addresses,"\n"
> 
> web_referrer.ip_addresses += ',203.190.235.96/27'
> web_referrer.ip_addresses.slice!('202.177.212.144/28')
> web_referrer.ip_addresses.sub!(/, *,/, ',')
> 
> web_referrer.ip_addresses = tempIp
> print web_referrer.ip_addresses, "\n"
> web_referrer.save!
> print "Saved ", web_referrer.ID, "\n"
> end
> ```

---

<div class="post-metadata">

**Author:** ![printmkr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9f8e36/32.png) [@printmkr](https://www.ruby-forum.com/u/printmkr)\
**Post date:** [January 2, 2008, 1:08pm UTC](https://www.ruby-forum.com/t/activerecord-migration-failing-to-save/124768/3 "2008-01-02T13:08:27Z")

</div>

Sussed it.  
I am supporting legacy code and the primary key column is ID not id.

The cure was:

class WebReferrer \< ActiveRecord::Base  
set\_table\_name :fred  
set\_primary\_key :ID  
end
