I want to insert a row into two tables that reference each other using not-nullable foreign key columns.
Let's say I have table A named make
make_id, bigint, (NOT NULL)
name, text
first_model_id, bigint, (NOT NULL)
referencesmodel.model_id
And a table B named model
model_id, (NOT NULL)
name, text
make_id, (NOT NULL)
referencesmake.make_id
Is it possible within a transaction to insert a row into both of these tables, even though each of the rows does not exist? This is easily doable by making one of the columns NULL
, inserting the first row, referencing it on the second insert, then getting the new row ID from the second insert.
I'm wondering if this is possible with columns that are NOT NULL
.