pardom-zz / ActiveAndroid

Active record style SQLite persistence for Android
http://www.activeandroid.com
4.7k stars 1.03k forks source link

Migration File : Delete a Column #434

Closed Artestico closed 8 years ago

Artestico commented 8 years ago

In the wiki it is mention that we can Delete a column Wiki : " If you want to change something in an existing table however (e.g. add or delete a column) "

And i have a problem with the Delete syntax and i try many option in the migration file but no one work

1/ ALTER TABLE DROP COLUMN ; =>android.database.sqlite.SQLiteException: near "DROP": syntax error (code 1): , while compiling: ALTER TABLE OutDoorMapMarker DROP COLUMN mapMarkerIconId

2/ ALTER TABLE DROP ; =>android.database.sqlite.SQLiteException: near "DROP": syntax error (code 1): , while compiling: ALTER TABLE OutDoorMapMarker DROP mapMarkerIconId

3/ ALTER TABLE DELETE ; =>android.database.sqlite.SQLiteException: near "DELETE": syntax error (code 1): , while compiling: ALTER TABLE OutDoorMapMarker DELETE mapMarkerIconId

4/ ALTER TABLE OutDoorMapMarker DELETE COLUMN mapMarkerIconId ; =>android.database.sqlite.SQLiteException: near "DELETE": syntax error (code 1): , while compiling: ALTER TABLE OutDoorMapMarker DELETE COLUMN mapMarkerIconId

jlhonora commented 8 years ago

From the sqlite docs:

The only schema altering commands directly supported by SQLite are the "rename table" and "add column" commands shown above

Take a look here: https://www.sqlite.org/lang_altertable.html . It details a way to implement remove column migrations, but it is definitely tricky.

Artestico commented 8 years ago

Thank you :+1: , i see this solution before , it is definitely tricky .. If There is not a command for DELETE COLUMN in the ActiveAndroid Library they should Change this part from the Wiki : " If you want to change something in an existing table however (e.g. add or delete a column) "

jlhonora commented 8 years ago

Sure, that was misleading, already changed it.