ben
ben

Reputation: 29787

If I change the type of a field in sqlite3 database, from string to text, will I lose the data in that field?

If I change the type of a field in my database via a Ruby on Rails migration, from string to text, will I lose the data in the field?

Upvotes: 1

Views: 381

Answers (2)

Pete
Pete

Reputation: 419

You will not lose data. String and text in SQLite are the same. There are really only five types in SQLite (NULL, INTEGER, REAL, TEXT, BLOB). Even if your field originally contained binary data (BLOB) and the database type was changed to TEXT the data is unchanged unless you store new data.

Upvotes: 1

pableu
pableu

Reputation: 3240

As far as I remember, SQLite uses the type only for input/output. Internally, everything is stored as text (that's why you can also store text in an int-field if you want). So no, it shouldn't remove any data, because it's only a superficial change.

No guarantees though, it's been a while since since I last worked with SQLite ;-)

This page explains SQLite's typing system nicely.

Upvotes: 6

Related Questions