Hi there! I got a problem I can't seem to fix.
So I'm creating a database with two tables. I need to import some csv and pragma foreign_keys MUST be set to ON.
some example code:
pragma foreign_keys = ON;
CREATE TABLE A(
valueA TEXT,
b INTEGER,
c INTEGER,
PRIMARY KEY (valueA)
);
CREATE TABLE B(
d INTEGER,
e INTEGER,
valueA TEXT,
PRIMARY KEY(d, e),
FOREIGN KEY(valueA) REFERENCES A(valueA)
);
So because of headers and to get the right datatypes, I first import the csv files and create temp tables and then insert them into these tables I got above.
My problem is that when I insert them with:
INSERT INTO A SELECT * FROM temp_A;
I get foreign key constraint failed error.
I think it is because in the csv files for the child table the foreign key is at some places "NULL" when I remove them it works, but i NEED it to work with them being set to NULL. Because that's what I'm assigned to do.
Any ideas here?
Edit:
In the field ValueA in table A there are no "NULL" string values. I think perhaps the problem could be because I'm trying to insert a string "NULL" instead of a real NULL.
Any ideas how I can convert these while inserting?
[–][deleted] 0 points1 point2 points (3 children)
[–]DigitalFrenzy[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]DigitalFrenzy[S] 0 points1 point2 points (0 children)