Skip to content Skip to sidebar Skip to footer

Drop A Column When The Schema Changes In Ormlite

I am working with Android and ORMLite. I am newbie and I upgrading the database to the Version 2. I have the class “Auto” and need to drop the column Alias. @DatabaseTable(

Solution 1:

This links help me to solve it.

Drop column in SQLite

FAQ SQLite 11

Delete column from SQL

save data before table upgrade

Drop table if it already exists and then re-create it?

SQLite has limited ALTER TABLE support that you can use to add a column to the end of a table or to change the name of a table. If you want to make more complex changes in the structure of a table, you will have to recreate the table. You can save existing data to a temporary table, drop the old table, create the new table, then copy the data back in from the temporary table.

For example, suppose you have a table named "t1" with columns names "a", "b", and "c" and that you want to delete column "c" from this table. The following steps illustrate how this could be done:

BEGIN TRANSACTION; 
CREATE TEMPORARY TABLE t1_backup(a,b);
INSERTINTO t1_backup SELECT a,b FROM t1; 
DROPTABLE t1; CREATETABLE t1(a,b); INSERTINTO t1 SELECT a,b FROM t1_backup;
DROPTABLE t1_backup; 
COMMIT;

The possible solution according to Phil's comments is this. 4

So your choices are:

  1. leave things as they are,

  2. add a new column, copying all the data from old to new as part of the upgrade, and just ignore the old column altogether, or

  3. Use a drop/create strategy to upgrade: back up the data from table into a temporary table, drop the table, re-create it as you'd like it to be, copy all the data back into it, and finally drop the temporary table.

Database upgrades are always nervous affairs (need lots of error handling, lots of testing), frankly if the name is the only thing that concerns you, I'd leave it alone (option 1). If you really need to change it then option 2 is low risk but leaves a 'dead' column and data lying around. Option 3 may be your choice if, for example, the data is a significant percentage of the overall database size.

I decided to delete the data from the column but don't drop the column, that is similar to solution 2.

Post a Comment for "Drop A Column When The Schema Changes In Ormlite"