SQLite Forum

How to remove a column and guide from the docs
Login
> Are there any recommendations how to implement migrations?
> I suppose people want to remove columns from time to time.

I script all my conversions.
Conversion scripts always look like:
```sql
.timeout 20000
BEGIN IMMEDIATE TRANSACTION;
-- not necessary, it is the default, 
-- but might not always be the default:
PRAGMA foreign_keys=off; 
-- conversion SQL here
-- always use explcit name lists, never SELECT *
COMMIT TRANSACTION;
```

and I run the script with 
  sqlite3 -bail database.sqlite <conversionscript

For renaming/adding/removing colums, I usually create a new database with the new schema, then populate it with something like:
```sql
ATTACH '/path/to/olddb.sqlite' AS olddb;
INSERT INTO main.newtable (col1,col2,...) SELECT col1,col2,... FROM olddb.oldtable ;
-- etcetera.
DETACH olddb;
```

If triggers would cause unwanted updates, I DROP them first and recreate them after the conversion.

A common "problem" is ownership and permissions of the database file, 
its -joourrnal, -shm, and/or -wal file and the directory they are in.

If you run a script with sqlite3 shell, this usually runs as 
another user than e.g. a webserver.

~~~
-- 
Regards,
Kees Nuyt
~~~