views:

31

answers:

2

I have a note field of string type in one of my models in my sqlite3 database, but I realized that I needed to store more text than string would allow.

I just ran a migration changing the type of the field from string to text. Looking at my database, it says that the type is now text(255), whereas before it was varchar(255).

What does the 255 mean? Is that a character limit? If so, would I have the same storage problems as before? How would I fix this?

Here is the migration I used to change the field type

change_column(:posts, :note, :text)
+1  A: 

You should just make your storage type text and not put any limit on it. The 255 denotes the maximum number of characters allowed in the field.

webdestroya
@webdestroya: Thanks for your answer. How do I do this? The migration I ran to change the type was change_column(:posts, :note, :text), so I didn't specify 255 myself.
ben
@ben - I'm not sure, perhaps try a `change_table` call, and do `:limit => nil`. Take a look at http://guides.rubyonrails.org/migrations.html#changing-tables
webdestroya
+1  A: 

SQLite does not enforce text storage limits. If you declare a column VARCHAR(1) or TEXT(1) you still can store some very long blob of 500 Megabytes inside it. Even though that is not adviseable.

~$ sqlite
SQLite version 3.7.2
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table foo ( bar text(3));
sqlite> insert into foo values ('aeiou');
sqlite> select * from foo;
aeiou
Benoit