frappe.exceptions.ValidationError: Currency can not be changed after making entries using some other currency

After pulling new code manually from git into ~/frappe-bench/apps/myapp, I tried to run migrate which failed with the following error. I have not touched anything related to currency in my code or during my setup except during the first time wizard when I set it to INR.

 $ bench --site testsite migrate                                        
Migrating user-dev                                                                                                                   
Updating DocTypes for frappe        : [========================================]                                                           
Updating DocTypes for erpnext       : [========================================]                                                           
Updating DocTypes for myapp         : [========================================]                                                           
Traceback (most recent call last):                                   
  File "/usr/lib/python3.8/runpy.py", line 193, in _run_module_as_main                                                                     
    return _run_code(code, main_globals, None,                                                                                                                                                                                                                                         
  File "/usr/lib/python3.8/runpy.py", line 86, in _run_code                                                                                
    exec(code, run_globals)                                          
  File "/home/user/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 97, in <module>                                      
    main()                                                           
  File "/home/user/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main                                          
    click.Group(commands=commands)(prog_name='bench')                                                                                      
  File "/home/user/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 764, in __call__                                
    return self.main(*args, **kwargs)                                                                                                      
  File "/home/user/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 717, in main                                    
    rv = self.invoke(ctx)                                                                                                                  
  File "/home/user/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1137, in invoke                                 
    return _process_result(sub_ctx.command.invoke(sub_ctx))                                                                                
  File "/home/user/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1137, in invoke    
    return _process_result(sub_ctx.command.invoke(sub_ctx))                                                                                
  File "/home/user/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)                                                                                         
  File "/home/user/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)                                 
  File "/home/user/frappe-bench/env/lib/python3.8/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)                                                                                       
  File "/home/user/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 25, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)                                                                                        
  File "/home/user/frappe-bench/apps/frappe/frappe/commands/site.py", line 239, in migrate
    migrate(context.verbose, rebuild_website=rebuild_website, skip_failing=skip_failing)                                                   
  File "/home/user/frappe-bench/apps/frappe/frappe/migrate.py", line 52, in migrate                                                  
    sync_fixtures()                                                  
  File "/home/user/frappe-bench/apps/frappe/frappe/utils/fixtures.py", line 23, in sync_fixtures
    import_doc(frappe.get_app_path(app, "fixtures", fname),                                                                                
  File "/home/user/frappe-bench/apps/frappe/frappe/core/doctype/data_import/data_import.py", line 60, in import_doc
    frappe.modules.import_file.import_file_by_path(f, data_import=True, force=True, pre_process=pre_process, reset_permissions=True)
  File "/home/user/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 65, in import_file_by_path
    import_doc(doc, force=force, data_import=data_import, pre_process=pre_process,                                                         
  File "/home/user/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 141, in import_doc
    doc.insert()                                                     
  File "/home/user/frappe-bench/apps/frappe/frappe/model/document.py", line 230, in insert
    self.run_before_save_methods()                                   
  File "/home/user/frappe-bench/apps/frappe/frappe/model/document.py", line 893, in run_before_save_methods
    self.run_method("validate")                                      
  File "/home/user/frappe-bench/apps/frappe/frappe/model/document.py", line 794, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)                                                                                         
  File "/home/user/frappe-bench/apps/frappe/frappe/model/document.py", line 1064, in composer
    return composed(self, method, *args, **kwargs)                                                                                         
  File "/home/user/frappe-bench/apps/frappe/frappe/model/document.py", line 1047, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))                                                                                   
  File "/home/user/frappe-bench/apps/frappe/frappe/model/document.py", line 788, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)                                                              
  File "/home/user/frappe-bench/apps/erpnext/erpnext/accounts/doctype/account/account.py", line 43, in validate
    self.validate_account_currency()                                 
  File "/home/user/frappe-bench/apps/erpnext/erpnext/accounts/doctype/account/account.py", line 161, in validate_account_currency
    frappe.throw(_("Currency can not be changed after making entries using some other currency"))
  File "/home/user/frappe-bench/apps/frappe/frappe/__init__.py", line 377, in throw                                                  
    msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable)
  File "/home/user/frappe-bench/apps/frappe/frappe/__init__.py", line 356, in msgprint
    _raise_exception()                                               
  File "/home/user/frappe-bench/apps/frappe/frappe/__init__.py", line 316, in _raise_exception
    raise raise_exception(msg)                                       
frappe.exceptions.ValidationError: Currency can not be changed after making entries using some other currency

Any ideas on how to debug this?

What happens if you try: bench update --reset ?

@smino, thanks for replying. It leads to an error that I reported in a separate post here.

Anybody have any suggestions on what could be going wrong here?

Why am I unable to migrate to the latest code? I’ve even tried to migrate back to the same state in git as before but it fails too.

This turned out to be a result of using fixtures to automatically create accounts.

bench migrate would try to remove existing accounts but since there were already transactions in the system, we would see this error.

The solution was to delete the fixtures folder from the system after installation.

1 Like