我有两个SQLite数据库,它们都有连接表来描述一对多的关系。现在这两个数据库需要通过某种导入/导出机制合并为一个,并仍然保持关系。
我尝试使用.dump将DB2转储,然后使用.read将其加载回DB1中,但总是收到“PRIMARY KEY must be unique”警告。
是否有最佳实践来处理这种情况?
首选不使用attach以避免额外的复杂性。
DB1
Fruit
-------------- | id | name | -------------- | 1 | Apple | | 2 | Lemon | | 3 | Kiwi | --------------
Juice ---------------- | id | name | ---------------- | 1 | Juice A | | 2 | Juice B | ----------------
Recipe (连接表)
---------------------------- | id | juice_id | fruit_id | ---------------------------- | 1 | 1 | 1 | | 2 | 1 | 2 | | 3 | 2 | 1 | | 4 | 2 | 3 | ----------------------------
DB2
Fruit
--------------- | id | name | --------------- | 1 | Kiwi | | 2 | Lemon | | 3 | Apple | | 4 | Orange | ---------------
Juice ---------------- | id | name | ---------------- | 1 | Juice C | | 2 | Juice D | ----------------
Recipe (连接表)
---------------------------- | id | juice_id | fruit_id | ---------------------------- | 1 | 1 | 1 | | 2 | 1 | 3 | | 3 | 2 | 2 | | 4 | 2 | 4 | ----------------------------
我尝试使用.dump将DB2转储,然后使用.read将其加载回DB1中,但总是收到“PRIMARY KEY must be unique”警告。
是否有最佳实践来处理这种情况?
首选不使用attach以避免额外的复杂性。
DB1
Fruit
-------------- | id | name | -------------- | 1 | Apple | | 2 | Lemon | | 3 | Kiwi | --------------
Juice ---------------- | id | name | ---------------- | 1 | Juice A | | 2 | Juice B | ----------------
Recipe (连接表)
---------------------------- | id | juice_id | fruit_id | ---------------------------- | 1 | 1 | 1 | | 2 | 1 | 2 | | 3 | 2 | 1 | | 4 | 2 | 3 | ----------------------------
DB2
Fruit
--------------- | id | name | --------------- | 1 | Kiwi | | 2 | Lemon | | 3 | Apple | | 4 | Orange | ---------------
Juice ---------------- | id | name | ---------------- | 1 | Juice C | | 2 | Juice D | ----------------
Recipe (连接表)
---------------------------- | id | juice_id | fruit_id | ---------------------------- | 1 | 1 | 1 | | 2 | 1 | 3 | | 3 | 2 | 2 | | 4 | 2 | 4 | ----------------------------
name
是唯一的吗?在合并后它们应该保持唯一吗? - CL.