IntegrityError: (1062, "Duplicate entry 'Sales Taxes and Charges Template' for key 'PRIMARY'")

So, I am trying to restore a database from v7.0.x to the same version, v7.0.x in my local.
The thing is after I successfully force restore, and after i do bench migrate
it return me an error
IntegrityError: (1062, "Duplicate entry 'Sales Taxes and Charges Template' for key 'PRIMARY'")
I checked table tabSales Taxes and Charges Template and there is only one row.
This is the full trace:

Executing erpnext.patches.v5_0.rename_taxes_and_charges_master in erpnext.vm (d56cb677eaab3383)
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, 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 "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 79, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 16, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", 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/core.py", 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/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 24, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 207, in migrate
    migrate(context.verbose, rebuild_website=rebuild_website)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 27, in migrate
    frappe.modules.patch_handler.run_all()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 26, in run_all
    if not run_single(patchmodule = patch):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 60, in run_single
    return execute_patch(patchmodule, method, methodargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 80, in execute_patch
    frappe.get_attr(patchmodule.split()[0] + ".execute")()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/patches/v5_0/rename_taxes_and_charges_master.py", line 7, in execute
    "Sales Taxes and Charges Template")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 639, in rename_doc
    return rename_doc(doctype, old, new, force=force, merge=merge, ignore_permissions=ignore_permissions)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/rename_doc.py", line 35, in rename_doc
    rename_parent_and_child(doctype, old, new, meta)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/rename_doc.py", line 87, in rename_parent_and_child
    (new, old))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database.py", line 137, in sql
    self._cursor.execute(query, values)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.IntegrityError: (1062, "Duplicate entry 'Sales Taxes and Charges Template' for key 'PRIMARY'")

Any idea???

open bench mysql
show me the output of this command
select name from tabSales Taxes and Charges Template;

@vishdha

+---------------+----------------------------+----------------------------+---------------+---------------+-----------+--------+-------------+------------+------+----------+---------------+------------+---------------+
| name          | creation                   | modified                   | modified_by   | owner         | docstatus | parent | parentfield | parenttype | idx  | disabled | title         | is_default | company       |
+---------------+----------------------------+----------------------------+---------------+---------------+-----------+--------+-------------+------------+------+----------+---------------+------------+---------------+
| Blank Charges | 2015-08-13 14:25:59.388479 | 2016-04-27 08:40:12.494293 | Administrator | Administrator |         0 | NULL   | NULL        | NULL       |   33 |        0 | Blank Charges |          0 | Energy Choice |
+---------------+----------------------------+----------------------------+---------------+---------------+-----------+--------+-------------+------------+------+----------+---------------+------------+---------------+

@vishdha I think I found the problem. On code erpnext.patches.v5_0.rename_taxes_and_charges_master
This is the code:
import frappe

def execute():
	if frappe.db.table_exists("Sales Taxes and Charges Master"):
		frappe.rename_doc("DocType", "Sales Taxes and Charges Master",
			"Sales Taxes and Charges Template")
		frappe.delete_doc("DocType", "Sales Taxes and Charges Master")

	if frappe.db.table_exists("Purchase Taxes and Charges Master"):
		frappe.rename_doc("DocType", "Purchase Taxes and Charges Master",
			"Purchase Taxes and Charges Template")
		frappe.delete_doc("DocType", "Purchase Taxes and Charges Master")

The thing is that table Sales Taxes and Charges Master exists, also table Sales Taxes and Charges Template also exists, so you can not rename to an database that already exists. But even when I try to delete Sales Taxes and Charges Template so it can be renamed still gives me this error.

How are deleting the “Sales taxes and Charges Template”? You need to delete from tabDocType and drop the table.

Fixed it. Thanks.