title: pq: insert or update on table violates foreign key constraint gorm
body: <p>I have three tables: AnaData, AnaStepData, and AnaStepInputData. Here are the model mappings for these tables:</p>
  <pre><code>type AnaData struct {
      ID                string             `gorm:&quot;primary_key;column:ana_ins_id&quot; validate:&quot;max=36&quot;`
      Name              string             `gorm:&quot;column:instance_nm&quot; validate:&quot;max=36&quot;`
      Description       string             `gorm:&quot;column:instance_desc&quot; validate:&quot;max=1000&quot;`
      AnaSteps          []AnaStepData      `gorm:&quot;foreignkey:ana_ins_id&quot;`
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/qwcR5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qwcR5.png" alt="enter image description here" /></a></p>
  <pre><code>type AnaStepData struct {
      ID               string                   `gorm:&quot;primary_key;column:ana_ins_step_id&quot; validate:&quot;max=36&quot;`
      StepName         string                   `gorm:&quot;column:step_nm&quot; validate:&quot;max=100&quot;`
      AnaInsID         string                   `gorm:&quot;column:ana_ins_id&quot; validate:&quot;max=36&quot;`
      InputParameters  []AnaStepInputData       `gorm:&quot;foreignkey:ana_ins_step_id&quot;`
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/NfGTs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NfGTs.png" alt="enter image description here" /></a></p>
  <pre><code>type AnaStepInputData struct {
      ID             string `gorm:&quot;primary_key;column:ana_ins_step_input_id&quot; validate:&quot;max=36&quot;`
      AnaStepID      string `gorm:&quot;column:ana_ins_step_id&quot; validate:&quot;max=36&quot;`
      ParameterName  string `gorm:&quot;column:ana_param_nm&quot; validate:&quot;max=100&quot;`
      ParameterValue string `gorm:&quot;column:param_value_txt&quot; validate:&quot;max=1000&quot;`
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/LPsSA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LPsSA.png" alt="enter image description here" /></a></p>
  <p>When I try to insert any values using &quot;db.Create(&amp;AnaData) into the AnaData table and respective child tables, I get the following error:</p>
  <blockquote>
  <p>pq: insert or update on table &quot;ana_ins_step_input&quot; violates foreign
  key constraint &quot;ana_ins_step_input_fk02&quot;</p>
  </blockquote>
  <p>Can anyone shed some light on what I am doing wrong?</p>