Modifying Table Structure
Adding, modifying, and deleting columns in existing tables.
🔧 Changing the Table Structure
Adding, deleting, or modifying columns of an existing table.
Via Admin Panel
- Tables → select a table
- Click «Structure» (or SQL query)
- Use the SQL query:
Add a Column
ALTER TABLE products ADD COLUMN discount INTEGER DEFAULT 0;
Delete a Column
SQLite does not directly support DROP COLUMN. Workaround:
-- 1. Create a new table without the column
CREATE TABLE products_new AS SELECT id, title, price FROM products;
-- 2. Drop the old table
DROP TABLE products;
-- 3. Rename the new table
ALTER TABLE products_new RENAME TO products;
Rename a Column
ALTER TABLE products RENAME COLUMN old_name TO new_name;
⚠️ Caution
- Backup: before ALTER TABLE, copy
cms.db - Data: deleting a column removes all data in it
- Related templates: after renaming, update Twig templates