Switch branches in V11 [ cannot import name Database issue]

i installed ERPNext V11 and when i run

bench switch-to-master
it told

Switched to master
Please run `bench update --patch` to be safe from any differences in database schema

but when i run it it gives me this error

Backing up sites...
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/opt/frappe/newerpnext/apps/frappe/frappe/utils/bench_helper.py", line 94, in <module>
    main()
  File "/opt/frappe/newerpnext/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/opt/frappe/newerpnext/env/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/opt/frappe/newerpnext/env/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/opt/frappe/newerpnext/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/frappe/newerpnext/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/frappe/newerpnext/env/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/frappe/newerpnext/env/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/opt/frappe/newerpnext/env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/opt/frappe/newerpnext/apps/frappe/frappe/commands/__init__.py", line 24, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/opt/frappe/newerpnext/apps/frappe/frappe/commands/site.py", line 293, in backup
    frappe.connect()
  File "/opt/frappe/newerpnext/apps/frappe/frappe/__init__.py", line 167, in connect
    from frappe.database import Database
ImportError: cannot import name Database

Please Help :frowning:

Hi,

The branch for v11 is “Staging” not “Master”. You should not switch back to Master before both are synchronized (in a few months maybe).

Did you install your site with the Develop branch before switching to Master ?

In this case I’m afraid you are experiencing the breaking changes from v12 and there is no solution except staying on Develop branch…

To clarify:

  • Master: v10
  • Staging: v11
  • Develop: v12

You can switch from a lower version to an upper version but not the other way around.

2 Likes

Did you run this command as mentioned i.e. bench update --patch

yes i did and i received this error

i returned back to frappe 10.1.49 and it worked :slight_smile:

Ok great!

1 Like

We are not switch to version 11.

how did u switched back to 10.1.49 ? from v11

i switched frappe to master and reinstalled my site

Guess like staging version is still generating lot of errors when upgrading.

Hoping for the stable version to be released soon (for master branch)

Excellent chdecultot!

To learn and confirm the above visit the repos and view the comments for those branches:

‘bumped to version 10.1.54’
GitHub - frappe/erpnext at master

'bumped to version 11.0.3-beta.2"
https://github.com/frappe/erpnext/tree/staging

‘version: move to 12.x.x-develop’
GitHub - frappe/erpnext: Free and Open Source Enterprise Resource Planning (ERP)

edit: May bad of course erpnext & frappe are a dependent pair of repos! But I failed to note this omission earlier and hence include frappe here - be sure that the branches of both repos match - use git status to confirm this.

bumped to version 10.1.50
GitHub - frappe/frappe at master

bumped to version 11.0.3-beta.6
https://github.com/frappe/frappe/tree/staging

GitHub - frappe/frappe: Low code web framework for real world applications, in Python and Javascript

OK, not sure how, but I’m on develop with my production ERPNext… How do I switch to v11, before database schema changes make it next-to-impossible?

To switch from ‘develop’ to ‘staging’ branch I did this -

frappe@ubuntu:~/frappe-bench/apps/erpnext$ git branch -a
* develop
master
remotes/origin/bcornwellmott-patch-1
remotes/origin/bcornwellmott-patch-2
remotes/origin/develop
remotes/origin/forellana-digithinkit-patch-1
remotes/origin/gh-pages
remotes/origin/hotfix
remotes/origin/master
remotes/origin/ppt_fix_qty
remotes/origin/revert-7409-daterangecontrol
remotes/origin/stock_reports
remotes/origin/v4.x.x
remotes/origin/v5.x.x
remotes/origin/v6.x.x
remotes/origin/v7.0.x
remotes/upstream/master
frappe@ubuntu:~/frappe-bench/apps/erpnext$ git config --unset-all remote.upstream.fetch

frappe@ubuntu:~/frappe-bench/apps/erpnext$ git config --add remote.upstream.fetch ‘+refs/heads/*:refs/remotes/upstream/*’

frappe@ubuntu:~/frappe-bench/apps/erpnext$ git fetch upstream
remote: Enumerating objects: 589, done.
remote: Counting objects: 100% (589/589), done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 766 (delta 566), reused 572 (delta 557), pack-reused 177
Receiving objects: 100% (766/766), 2.62 MiB | 1.97 MiB/s, done.
Resolving deltas: 100% (627/627), completed with 381 local objects.
From GitHub - frappe/erpnext: Free and Open Source Enterprise Resource Planning (ERP)
* [new branch] coverage-badge → upstream/coverage-badge
* [new branch] develop → upstream/develop
* [new branch] hotfix → upstream/hotfix
* [new branch] intellisense-fix → upstream/intellisense-fix
* [new branch] python3-super-fix → upstream/python3-super-fix
* [new branch] staging → upstream/staging
* [new branch] staging-fixes → upstream/staging-fixes
* [new branch] v4.x.x → upstream/v4.x.x
* [new branch] v5.x.x → upstream/v5.x.x
* [new branch] v6.x.x → upstream/v6.x.x
* [new branch] v7.0.x → upstream/v7.0.x
* [new branch] v7.x.x → upstream/v7.x.x
* [new branch] v8.x.x → upstream/v8.x.x
* [new branch] v9.x.x → upstream/v9.x.x
* [new branch] validate-fy-dates-1 → upstream/validate-fy-dates-1
* [new tag] v11.0.3-beta.2 → v11.0.3-beta.2
* [new tag] v11.0.1 → v11.0.1
* [new tag] v11.0.2 → v11.0.2
* [new tag] v11.0.3 → v11.0.3

frappe@ubuntu:~/frappe-bench/apps/erpnext$ git branch -a
* develop
master
remotes/origin/bcornwellmott-patch-1
remotes/origin/bcornwellmott-patch-2
remotes/origin/develop
remotes/origin/forellana-digithinkit-patch-1
remotes/origin/gh-pages
remotes/origin/hotfix
remotes/origin/master
remotes/origin/ppt_fix_qty
remotes/origin/revert-7409-daterangecontrol
remotes/origin/stock_reports
remotes/origin/v4.x.x
remotes/origin/v5.x.x
remotes/origin/v6.x.x
remotes/origin/v7.0.x
remotes/upstream/coverage-badge
remotes/upstream/develop
remotes/upstream/hotfix
remotes/upstream/intellisense-fix
remotes/upstream/master
remotes/upstream/python3-super-fix
remotes/upstream/staging
remotes/upstream/staging-fixes
remotes/upstream/v4.x.x
remotes/upstream/v5.x.x
remotes/upstream/v6.x.x
remotes/upstream/v7.0.x
remotes/upstream/v7.x.x
remotes/upstream/v8.x.x
remotes/upstream/v9.x.x
remotes/upstream/validate-fy-dates-1

frappe@ubuntu:~/frappe-bench/apps/erpnext$ git checkout staging
error: Your local changes to the following files would be overwritten by checkout:
erpnext/accounts/doctype/sales_invoice/sales_invoice.py
erpnext/controllers/buying_controller.py
Please, commit your changes or stash them before you can switch branches.
Aborting
frappe@ubuntu:~/frappe-bench/apps/erpnext$ git status
On branch develop
Changes not staged for commit:
(use “git add …” to update what will be committed)
(use “git checkout – …” to discard changes in working directory)

modified:   erpnext/accounts/doctype/sales_invoice/sales_invoice.py
modified:   erpnext/controllers/buying_controller.py
modified:   erpnext/controllers/selling_controller.py

no changes added to commit (use “git add” and/or “git commit -a”)

frappe@ubuntu:~/frappe-bench/apps/erpnext$ git reset --hard
HEAD is now at dc4c83a Merge branch ‘develop’ of GitHub - frappe/erpnext: Free and Open Source Enterprise Resource Planning (ERP) into develop

frappe@ubuntu:~/frappe-bench/apps/erpnext$ git checkout staging
Branch staging set up to track remote branch staging from upstream.
Switched to a new branch ‘staging’

frappe@ubuntu:~/frappe-bench/apps/erpnext$ git status
On branch staging
Your branch is up-to-date with ‘upstream/staging’.
nothing to commit, working directory clean

frappe@ubuntu:~/frappe-bench/apps/erpnext$ git branch -a
develop
master
* staging
remotes/origin/bcornwellmott-patch-1
remotes/origin/bcornwellmott-patch-2
remotes/origin/develop
remotes/origin/forellana-digithinkit-patch-1
remotes/origin/gh-pages
remotes/origin/hotfix
remotes/origin/master
remotes/origin/ppt_fix_qty
remotes/origin/revert-7409-daterangecontrol
remotes/origin/stock_reports
remotes/origin/v4.x.x
remotes/origin/v5.x.x
remotes/origin/v6.x.x
remotes/origin/v7.0.x
remotes/upstream/coverage-badge
remotes/upstream/develop
remotes/upstream/hotfix
remotes/upstream/intellisense-fix
remotes/upstream/master
remotes/upstream/python3-super-fix
remotes/upstream/staging
remotes/upstream/staging-fixes
remotes/upstream/v4.x.x
remotes/upstream/v5.x.x
remotes/upstream/v6.x.x
remotes/upstream/v7.0.x
remotes/upstream/v7.x.x
remotes/upstream/v8.x.x
remotes/upstream/v9.x.x
remotes/upstream/validate-fy-dates-1
frappe@ubuntu:~/frappe-bench/apps/erpnext$

To switch frappe I only had to do this:

frappe@ubuntu:~/frappe-bench/apps/frappe$ git checkout staging
M frappe/init.py
Branch staging set up to track remote branch staging from upstream.
Switched to a new branch ‘staging’

frappe@ubuntu:~/frappe-bench/apps/frappe$ git branch -a
develop
master
* staging
remotes/upstream/HEAD → upstream/develop
remotes/upstream/adityahase-coverage-badge
remotes/upstream/allow_quick_entry_fields
remotes/upstream/auto-repeat-schedule
remotes/upstream/codingCoffee-patch-1
remotes/upstream/coverage-unexecuted-fix
remotes/upstream/develop
remotes/upstream/frappe-chat
remotes/upstream/hof
remotes/upstream/hotfix
remotes/upstream/issue_result
remotes/upstream/kickbot
remotes/upstream/mac-address-restrict
remotes/upstream/manassolanki-patch-1
remotes/upstream/master
remotes/upstream/post-list-view
remotes/upstream/raghukamath-patch-1
remotes/upstream/revert-4133-grid
remotes/upstream/revert-4685-hotfix-xss-v10
remotes/upstream/revert-5486-hotfix
remotes/upstream/revert-5556-apply-user-permission-to-treeview
remotes/upstream/revert-5767-modules-dropdown
remotes/upstream/revert-5872-update_billing_details
remotes/upstream/staging
remotes/upstream/staging-fixes
remotes/upstream/trim_tables-docstring
remotes/upstream/v4.x.x
remotes/upstream/v5.x.x
remotes/upstream/v6.x.x
remotes/upstream/v7.0.x
remotes/upstream/v7.x.x
remotes/upstream/v8.x.x
remotes/upstream/v9.x.x

1 Like

If you are shifting between branches and facing this error (I face this error when I switch to develop and then back to staging-fixes), run the following command

# if you are in frappe-bench folder
frappe-bench > cd apps/frappe
frappe-bench/apps/frappe > find . -name "*.pyc" -exec rm -f {} \;

Basically, all the .pyc needs to be rebuild because of changes in lots of core files.

10 Likes

after replacing ` to " in Clarke’s example, things started going forward.
Finally I was able to do bench switch-to-branch staging, and then after bench update --reset, I’m on what it seems to be 11.0.3

Thanks.

What happens now after 11 goes out of beta?

Hi all,
For anyone else that might be running into this specific error (“ImportError: cannot import name Database”)issue,
The problem is from an empty “database” directory(with probably a .pyc file) that may have been created from previous git pulls. Since git doesn’t track empty directories, the directory just sits there doing nothing posing as the original module alongside the main “database.py” module.

Solution:
Just delete the empty directory (I think this should be safe since the dir is not being tracked)

Hope it helps someone.

4 Likes