[ACCEPTED]-storing more than 255 characters in a PostgreSQL DB on heroku-heroku

Accepted answer
Score: 24

use text instead of string on your migration type.

To 1 change a migration

  1. script/generate migration change_string_to_text
  2. change_column :model, :attribute, :text
  3. rake db:migrate
Score: 9

Just to expand on @Codeglot's answer, :text is 11 for (essentially) unlimited-length strings. :string with 10 a limit:1234 option will limit the string to that 9 length. On Postgres, a :string, limit:nil is effectively 8 synonymous with :text. Although some databases 7 store VARCHAR, VARCHAR(n), and TEXT types 6 in different ways, leading to performance 5 considerations, Postgres stores them all 4 in the same way.

So if you want to exceed 3 255 chars but not be completely unbounded, you can 2 use :string, limit:1234. Alternatively, you can use :text and restrict 1 the length via validations.

More Related questions