ImportError changing custom app name

I have a custom app installed and want to change its name, but when I run the bench migrate command the ImportError: No module named appears.

I have modified the file ~/frappe-bench/sites/apps.txt and have put the new app name. Also, I have changed the name of the directory of my custom app in ~/frappe-bench/apps/.

I’m not sure what are the right steps, so I would like you to describe to me the steps to follow, because I can’t use my custom app now.

Go to Module Def Table and change the old name to your new name.

Also, change the Module value in reports, doctypes, print format, wherever used.

When I go there and try to change the old name to the new name, I get the ImportError: No module named error. Maybe I have to define the new name in another place more.

I don’t know what happened with your last post, anyway I followed your steps and I think I did it. I was able to change the old name to the new name in Module Def.
The only error that I get is ImportError: No module named with the old name of the app, I don’t know why.

I deleted it. I think it was not correct and I may have left out something.

Have you updated the Module value in the Custom app doctypes, reports, print format, etc ?

Yes, I updated it.

Also I have used bench migrate and bench restart commands and now I only receive Internal Server Error from the system.

Post the traceback or error message here.

This is the only thing that is displayed in the web browser:

This is the output of bench migrate command:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/", line 64, in get_app_commands
    app_command_module = importlib.import_module(app + '.commands')
  File "/usr/lib/python2.7/", line 37, in import_module
ImportError: No module named cleceim_management.commands
Traceback (most recent call last):
  File "/usr/lib/python2.7/", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/", line 72, in _run_code
    exec code in run_globals
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/", line 94, in <module>
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/", line 18, in main
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/", line 697, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/", line 24, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/", line 219, in migrate
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 158, in init
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 872, in setup_module_map
    for module in get_module_list(app)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 746, in get_module_list
    return get_file_items(os.path.join(os.path.dirname(get_module(app_name).__file__), "modules.txt"))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 704, in get_module
    return importlib.import_module(modulename)
  File "/usr/lib/python2.7/importlib/", line 37, in import_module
  ImportError: No module named cleceim_management

The module name cleceim_management is the old name.

If this exists in the tabModule Def table remove it.

If this exists anywhere in the apps folder, replace it by the new custom app name

then bench migrate

How can I access that table through the terminal?

I have tried to replace it in all the places where it could be, I think I haven’t left anything, even so the bench migrate command keeps returning the same error.

First try bench uninstall-app does it remove all the traces of your old app or not ? If yes, then all is okay. SImply reinstall new app.

via bench mariadb

delete from tabModule Def where name = 'cleceim_management'

For tabDocType, tabReport, tabPrint Format and others, you can update the value wherever the module value is ‘cleceim_management’

UPDATE tabDocType set module = 'your_module_name' where module = 'cleceim_management'

Here are the possible tables you may have to update, depending on the features you made:

MariaDB [4c5ff27eaf7116a8]> select parent from `tabDocField` where fieldname = 'module';
| parent              |
| Block Module        |
| DocType             |
| Website Theme       |
| Print Format        |
| Data Migration Plan |
| Page                |
| Report              |
| Notification        |
| Web Form            |

it means this value is still there in the database

The bench uninstall-app command returns the same ImportError: No module named error.

When I execute that command, the system doesn’t detect it as a correct option for the bench command.

Okay, I had to use the bench mysql command instead of bench mariadb.

After executing the previous line, it returns:

Query OK, 0 rows affected

I have tried to update all the tables that return the previous query, and they all return the same result:

Query OK, 0 rows affected
Rows matched: 0  Changed: 0  Warning: 0

This is a little messy. I have discovered why cleceim_management doesn’t appear in any of the modules listed by the query:

SELECT parent FROM tabDocField WHERE fieldname='module';

I created cleceim_management only as a Custom App, but the modules are others.

I’ll explain why used that query. I wrote that query to notify which features in ERPnext contain a field called Module. Now say you created the app, made custom doctypes, reports and page so now you will know will have to remember what features you made in that app and are now having the old name of the app.

To expand the search a little more I have made this query:

SELECT parent, fieldname FROM `tabDocField`
WHERE fieldname IN ('app_name','app','module_name','module')
GROUP BY parent, fieldname;

And the search has returned this to me:

| parent              | fieldname   |
| Block Module        | module      |
| Data Migration Plan | module      |
| Desktop Icon        | app         |
| Desktop Icon        | module_name |
| DocType             | app         |
| DocType             | module      |
| Email Alert         | module      |
| Module Def          | app_name    |
| Module Def          | module_name |
| OAuth Client        | app_name    |
| Page                | module      |
| Print Format        | module      |
| Report              | module      |
| Test Runner         | app         |
| Web Form            | module      |
| Website Theme       | module      |

I have found that the Desktop Icon table has several entries with the app field filled with the value cleceim_management. I made the following query, but the problem keeps appearing:

UPDATE `tabDesktop Icon` set app='my_module_name' WHERE app='cleceim_management';

I have not found more features related to cleceim_management.

The function that returns the error ImportError: No module named is __import__ when passing it cleceim_management as an argument.

How exactly does this function work?
How does the sys.modules dictionary work?
Where do the __import__ function look for the modules?

Maybe I could do something to allow bench uninstall command to delete the module correctly.