gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.3k stars 279 forks source link

sqlite drop column #943

Open nextonphotos opened 1 month ago

nextonphotos commented 1 month ago

I can't seem to find a good way to drop a column in sqlite. Dropping a column with SQL is only supported in newer versions of sqlite than what some of the servers I have to work with support.

A comment in SQLiteWriter says, "In SQLite we can't change columns, drop columns, change or add foreign keys so we have a table-rebuild function."

There are functions available to do some of these things using get and put table, but I can't figure out how to drop a column. What am I missing? Any suggestions on how to do this, or is this functionality currently not available?

Lynesth commented 1 month ago

RedBeanPHP isn't responsible for what's available or not in SQLite version and does not provide any polyfill for missing features, unless those would be fundamental for RedBean's inner workings.

If your SQLite version doesn't support DROP COLUMN, then you'll have to create a new table, copy the data, delete the old table and rename the new one. You can find examples online as to how you can do this, such as this one on SO: https://stackoverflow.com/questions/5938048/drop-column-from-sqlite-table/5987838#5987838