Create a foreign key to a table that doesn't exist in postgres I'm trying to put together a solution where I have a bunch of script files that contain my schema creation. Something similar to Visual Studio's SQL Project, but for Postgres.

My problem is that the files won't necessarily be read in the correct order, for instance the first file/script/table read has a dependency on the 2nd file/script/table.

I was hoping there was some way I could disable the check to see if the referred table/column does exist, creating all the tables, and then re-enabling the check.

I'm running 9.2.24

My 2nd solution would be to order the files in such a way that it does only create a table when the dependencies already exist, but my above mention method would be preferred.
Not possible. The source and target of a foreign key constraint must exist when you create the foreign key. 

The usual solution to that problem is, to have all foreign keys in a separate script that is run after all tables have been created. Not together with each table.