Reputation: 45941
After finding 2 SO questions related to string vs. text fields, I discovered that the link field is already text:
create_table "answers", :force => true do |t|
t.string "text"
t.text "link"
Why is Postgres throwing the following error:
ActiveRecord::StatementInvalid: PG::Error: ERROR: value too long for type character varying(255)
I tried a migration change_column :answers, :link, :text, :limit => nil
but I don't think that does anything.
Edit: So, the problem is that the schema says the field is text, but actually it is string:
Answer.new.column_for_attribute('link').type
=> :string
What is the best way to fix it? By rebuilding the database from the schema? By changing it to string and then back to text?
Rails 3.2.2, Postgres 9, Heroku.
Upvotes: 3
Views: 2526
Reputation: 45941
Not quite sure how it happened, but one of the following:
Upvotes: 1
Reputation: 35318
Write your migration using raw SQL statements sent to Postgres. Just call execute
with whatever you'd run directly in the psql console. It's the best way to know exactly what state your DB is going to be left in. Often this is a better solution than letting Rails define your schema for you. You should really look at your schema regularly, especially after running a migration.
Upvotes: 0