Python 3.x 如何将两个SQLite3数据库相互合并

Python 3.x 如何将两个SQLite3数据库相互合并,python-3.x,sqlite,Python 3.x,Sqlite,嗨,我正在尝试合并两个数据库。 我有以下代码来搜索数据库,然后合并它们 import os import glob import sqlite3 con3 = sqlite3.connect("./combine.SQL") #Empty DB directory_with_databases = "./unpacked/" #folder with "full" *.sql dbs databases = glob.glob(os.path.join(directory_with

嗨,我正在尝试合并两个数据库。 我有以下代码来搜索数据库,然后合并它们

import os
import glob
import sqlite3


con3 = sqlite3.connect("./combine.SQL")  #Empty DB


directory_with_databases = "./unpacked/" #folder with "full" *.sql dbs


databases = glob.glob(os.path.join(directory_with_databases, "*.SQL"))


for filename in databases:
    con3.execute("ATTACH ? as dba", (filename,))

    for row in con3.execute ("SELECT * FROM dba.sqlite_master WHERE type='table'") :
        combine = "INSERT INTO " + row[1] + " SELECT * FROM dba." + row[1]
        print (combine)
        con3.execute (combine)

    con3.commit ()

    con3.execute("detach database dba")
执行代码时,我得到以下错误:

con3.execute (combine)
sqlite3.IntegrityError: UNIQUE constraint failed: PLschemaVersions.ID

有人能帮我完成代码吗

插入有冲突的行时,您希望发生什么情况?从开始提供一些自动处理此类情况的选项。@Shawn我唯一希望发生的事情是将具有相同布局的数据库合并在一起。因此,如果您知道其他方法,请告诉我:-)请提供有关要合并的表的架构的一些详细信息,例如使用
.schema