开发者

string/text storage limits in a sqlite3 database

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?

H开发者_运维知识库ere is the migration I used to change the field type

change_column(:posts, :note, :text)


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜