Now that my Custom App has reached a stage where its database structure has become stable and probably will not change any more.
But when I checked the tables of the DocType that I have created I found that there are many fields which do not exist any more in my DocTypes.
I want to get rid of all these fields and also there are a few tables (that got created when I created a few Dummy DocTypes) that I need to get rid of.
Please make sure that you use this method very carefully as it involves altering the database and any mistakes can lead to severe consequences like breaking the entire site.
Itâs highly recommended that you dry run the command before executing it;
administrator@dellpc:~/frappe-bench14$ bench --version
5.14.3
administrator@dellpc:~/frappe-bench14$ bench list-apps
frappe 14.4.2 version-14
erpnext 14.0.2 version-14
administrator@dellpc:~/frappe-bench14$ bench trim-tables
Taking backup for erp14
Backup Summary for erp14 at 2022-09-08 17:37:01.677219
Config : ./erp14/private/backups/20220908_173659-erp14-site_config_backup.json 180.0B
Database: ./erp14/private/backups/20220908_173659-erp14-database.sql.gz 1.3MiB
Public : ./erp14/private/backups/20220908_173659-erp14-files.tar 10.0KiB
Private : ./erp14/private/backups/20220908_173659-erp14-private-files.tar 10.0KiB
Ignoring missing table for DocType: test
Consider removing record in the DocType table for test
The following data have been removed from erp14
+---------+--------+
| DocType | Fields |
+---------+--------+
But this is an unprofessional work around at the moment. And doing this is resulting in loss of data so I have to enter all the master data again before I can use the Custom App.
@YogiYang Iâm currently working on re-writing this for v13. When Iâm finished, I will share the code in a public GitHub Gist. It wonât be a Bench/Click CLI command. But youâll be able to run it with 'bench execute' .
Youâll need to add this to a Python module somewhere (probably in your own App)
You cannot use ordinary "bench <command>" syntax. Achieving that is a bit harder, because you have to teach Bench where to find the new Click commands.
Instead, in each functionâs docstring, Iâve tried to include a few examples of a 'bench executeâ command.
For example, to remove extra columns from the âCustomerâ DocType: