Your insert statement is likely to violate the constraint in the new table. There may be a primary key constraint, a unique constraint, a foreign key constraint (if you use PRAGMA foreign_keys = ON; ), etc.
You fix it either by removing the restriction, fixing the data, or deleting the data. Removing a constraint is usually bad, but it depends on the application.
Is there a good reason to copy data one row at a time, and not as a set?
INSERT INTO new_table SELECT column_list FROM old_table;
If you need help defining a constraint, edit the original question and post the result of these two SQLite queries.
select sql from sqlite_master where tbl_name = 'old_table_name'; select sql from sqlite_master where tbl_name = 'new_table_name';
Update:. Based on the results of these two queries, I see only one restriction - the primary key restriction in each table. If you have not created triggers in these tables, the only restriction that may fail is the primary key restriction. And the only way a constraint can fail is to try inserting two lines that have the same meaning for pk.
I guess this can happen in several different ways.
- The old table has duplicate values ββin the "pk" column.
- The code that performs your migration modifies or enters a duplicate value before inserting data into a new table.
- Another process, possibly another computer running, inserts or updates data without your knowledge.
- Other reasons I haven't thought about yet. :-)
You can determine if there are duplicate pk values ββin the old table by running this query.
select pk from old_table_name group by pk having count() > 1;
Perhaps you should try to manually transfer data using INSERT INTO . . . SELECT . . . INSERT INTO . . . SELECT . . . If this fails, add a WHERE clause to reduce the size of the set until you isolate the bad data.
Mike Sherrill 'Cat Recall'
source share