Search code examples
ruby-on-railssqliteheroku

Rails 3/Heroku - Error resetting database on push to heroku - 'type modifier is not allowed for type "text"'


I'm trying to heroku rake db:reset from a Rails 3 app using sqlite3, but I'm getting the following error:

rake aborted!
PGError: ERROR:  type modifier is not allowed for type "text"
LINE 1: ...ary key, "name" character varying(255), "content" text(255),...
                                                             ^

here is my most recent migration:

change_table :mixes do |t|
  t.change :content, :text
  t.change :post, :text  
end 

and my schema.rb:

create_table "mixes", :force => true do |t|
  t.string   "name"
  t.text     "content",    :limit => 255
  t.datetime "created_at"
  t.datetime "updated_at"
  t.string   "mixologist"
  t.string   "link"
  t.string   "title"
  t.text     "post",       :limit => 255
end

From my understanding Sqlite3 doesn't enforce limits on string and text and I didn't add those limits myself. I thought Heroku would automatically handle those in converting to Postgres or whatever it does. But it seems like the limits are throwing it off somewhere. What's the best way for me to deal with this?

Let me know if I should post anything else.


Solution

  • Change your recent migration to

    change_table :mixes do |t|   
        t.change :content, :text, :limit => nil
        t.change :post, :text, :limit => nil
    end
    

    This is one of the many nuances you will have to look out for when developing using sqlite3 :( Only happens when you alter the type of a column from string to text.