Hi All,
I'm trying to migrate a database from sqlite to mysql and am having
some migration issues with foreign key references.

In my original tables I have entries that have been deleted:

table 1
id      value
1       a
2       b
3       c
5       e

(where the entry id=4 has been deleted)

When I export this table it looks as above, but when I re-import it I
get:

table 1
id      value
1       a
2       b
3       c
4       e

Here it updates the index so the old index=5 is now =4

The problem seems to be that in a subsequent table the original data
referred to the old index of table 1

table 2
id     ref_to_table_1     value
1        1                      x
2        5                      y
3         3                     z

when I import this table, web2py gives me an error saying that I can't
reference id=5 in table 1 because it does not exist.

The error I get from importing to mysql is:
IntegrityError: (1452, 'Cannot add or update a child row: a foreign
key constraint fails (`fwv8`.`food_nutrient_link`, CONSTRAINT
`food_nutrient_link_ibfk_1` FOREIGN KEY (`food_id`) REFERENCES `food`
(`id`) ON DELETE CASCADE)')

Is there any graceful way to handle this?
Thanks!
--Peter

Reply via email to