title: Insert or update on table violates foreign key constraint TelephoneContact
body: <h1>Objective</h1>
  <p>Create inside the <code>telephones</code> table when I create the <code>client</code>.</p>
  <h1>What happening</h1>
  <p>I have 3 tables, called <code>clients</code>, <code>contacts</code>, and <code>telephones</code>. Following this image, we can see that the <code>owner_id</code> can be <code>contacts.id</code> and/or <code>clients.id</code>. But when I try to create the <code>client</code>, the <code>client</code> is created but not inserted data inside the <code>telephones</code> tables. But show this error</p>
  <pre><code>{
    &quot;error&quot;: &quot;insert or update on table \&quot;telephones\&quot; violates foreign key constraint \&quot;TelephoneContact\&quot;&quot;
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/thnxJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/thnxJ.png" alt="Relationship" /></a></p>
  <h1>Migration</h1>
  <pre><code>import {
    MigrationInterface,
    QueryRunner,
    TableColumn,
    TableForeignKey,
  } from 'typeorm';
  
  export default class AddOwnerIdToTelephones1597250413640
    implements MigrationInterface {
    public async up(queryRunner: QueryRunner): Promise&lt;void&gt; {
      await queryRunner.addColumn(
        'telephones',
        new TableColumn({
          name: 'owner_id',
          type: 'uuid',
          isNullable: false,
        }),
      );
  
      await queryRunner.createForeignKey(
        'telephones',
        new TableForeignKey({
          name: 'TelephoneClient',
          columnNames: ['owner_id'],
          referencedColumnNames: ['id'],
          referencedTableName: 'clients',
          onDelete: 'CASCADE',
          onUpdate: 'CASCADE',
        }),
      );
  
      await queryRunner.createForeignKey(
        'telephones',
        new TableForeignKey({
          name: 'TelephoneContact',
          columnNames: ['owner_id'],
          referencedColumnNames: ['id'],
          referencedTableName: 'contacts',
          onDelete: 'CASCADE',
          onUpdate: 'CASCADE',
        }),
      );
    }
  
    public async down(queryRunner: QueryRunner): Promise&lt;void&gt; {
      await queryRunner.dropForeignKey('telephones', 'TelephoneContact');
      await queryRunner.dropForeignKey('telephones', 'TelephoneClient');
      await queryRunner.dropColumn('telephones', 'owner_id');
    }
  }
  </code></pre>
  <h1>Telephone Model</h1>
  <pre><code>import {
    PrimaryGeneratedColumn,
    Column,
    Entity,
    ManyToOne,
    JoinColumn,
  } from 'typeorm';
  
  import Client from './Client';
  import Contact from './Contact';
  
  @Entity('telephones')
  class Telephone {
    @PrimaryGeneratedColumn('uuid')
    id: string;
  
    @Column()
    telephone_number: string;
  
    @ManyToOne(() =&gt; Client, client =&gt; client.id)
    @ManyToOne(() =&gt; Contact, contact =&gt; contact.id)
    @JoinColumn({ name: 'owner_id' })
    owner_id: string;
  }
  
  export default Telephone;
  
  </code></pre>