Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change data base schema

Tags:

sqlite

I am using sqlite older version for developing my application.

For some problem i have altered one of the table for adding new column. Previously this table data is stored in integers, after altering the table they have changed to strings. How can I get the altered string data again to integers, while querying how to query these fields?

like image 254
DivyaTalluri Avatar asked Nov 14 '11 05:11

DivyaTalluri


1 Answers

SQLite only allows very limited changes to be done to an existing table. For anything else, you should:

  1. rename the old table,
  2. make a new table with the old name and with the correct column definitions,
  3. copy the data over, and
  4. drop the old table.

Do this within a single transaction, of course! Also, practice on another database before trying this with your production data.

like image 199
Donal Fellows Avatar answered Sep 23 '22 15:09

Donal Fellows