I have two tables, let’s call them charts and charts_tree. The charts_tree.idDir (auto-increment, integer) column is constrained to charts.chart_tree_dir. Both tables are InnoDB based.
Now I am trying to insert a row in charts_tree with null value for idDir (due to its auto-increment nature), but I am getting a foreign constrain fails error message on this column. How is this possible, considering that both tables are blank initially and there are no interconnected columns?
Is the foreign key constraint on the idDir column and references the chart_tree_dir column ?
That’s what I understood from what you said ; if that’s the case, when you try to insert a row in charts_tree, the auto_incremented value generated by mysql is not present in charts at the moment of creation (since both tables are blank), thus the foreign key failing.
It should be the other way around I think.