0

I am having an issue with Heroku in regards to adding an integer column to an existing table.

Here is how I setup my migration file:

class AddFieldsToNetwork < ActiveRecord::Migration
  def self.up
    add_column :networks, :phone, :integer, :limit => 10
    add_column :networks, :contact, :string
  end

def self.down
  remove_column :networks, :phone
  remove_column :networks, :contact
  end
 end

Now this works locally, but when I push to Heroku, I get what most people get:

!!! Caught Server Exception  
HTTP CODE: 500  
Taps Server Error: PGError: ERROR:  integer out of range

If I change :integer to :string, then adding the columns works and functions great on Heroku. If I leave it under :integer, the :network model crashes when I create new "network".

Can anyone tell me what I might be doing wrong?

5
  • Sorry for the terrible formatting Commented Mar 13, 2012 at 22:09
  • What version of Ruby are you using locally? There's an issue with taps that causes similar errors if you're using 1.9.3 locally but pushing to a server using 1.9.2 (Heroku uses 1.9.2). Commented Mar 13, 2012 at 22:11
  • Currently using ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0] Commented Mar 13, 2012 at 22:13
  • @RubyNewbie: Regarding the code format: you need a newline before the indented code block. Have a look what I changed, click on edited ... above my name. Commented Mar 14, 2012 at 1:45
  • Thanks Erwin. Much more presentable. Commented Mar 14, 2012 at 16:17

1 Answer 1

1

:limit - Requests a maximum column length. This is number of characters for :string and :text columns and number of bytes for :binary and :integer columns.

For phone you definitely use strings, reason is you mean 10 characters. Not bytes for numbers

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Alisher. Sorry for another newbie question....then in regards to :phone, if I do not want to allow the user to write any Alpha character, just make a rule in the controller?
You should add validations in the model not controller. Search for validation gems on rubygems.org before writing custom validations.

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.