title: Avoiding cyclic dependency - two tables reference each other in CREATE statement - PostgreSQL
body: <p>In my postgresql assignment I have to write something like this:</p>
  
  <pre><code>CREATE TABLE Coffee (
      name VARCHAR(30) PRIMARY KEY,
      body VARCHAR(10),
      referencepod INTEGER REFERENCES CoffeePod(modelnr)
  );
  
  CREATE TABLE CoffeePod(
      modelnr INTEGER PRIMARY KEY, 
      material VARCHAR(30) NOT NULL, 
      contains VARCHAR(30) REFERENCES Coffee(name),
  );
  </code></pre>
  
  <p>i.e:</p>
  
  <blockquote>
    <p>Each coffee has one coffee pod that serves as “reference pod” for this
    coffee</p>
  </blockquote>
  
  <p>But only these two lines confuse me: 
  <code>referencepod INTEGER REFERENCES CoffeePod(modelnr)</code> and <code>contains VARCHAR(30) REFERENCES Coffee(name)</code></p>
  
  <p>When I add those two lines to <code>psql</code> I get either <code>ERROR:  relation "Coffee" does not exist</code> or <code>ERROR:  relation "CoffeePod"</code> does not exist because of course they depend of each other. </p>
  
  <p>I guess I should use <code>ALTER TABLE</code> but in my assignment they wrote a hint: </p>
  
  <blockquote>
    <p>You can implement these changes directly in the CREATE statements.</p>
  </blockquote>
  
  <p>Is it even possible for two tables to reference each other in <code>CREATE</code> statement or did I misunderstood this? </p>