title: Postgres and Sequelize - SequelizeUniqueConstraintError
body: <p>I have this table:</p>
  <pre><code>CREATE TABLE &quot;wf&quot;.&quot;WorkflowAssignationContact&quot; (
  &quot;workflowAssignationId&quot; int4 NOT NULL,
  &quot;contactId&quot; int4 NOT NULL,
  &quot;contactNumber&quot; varchar NOT NULL,
  CONSTRAINT &quot;WorkflowAssignationContact_contactId_fkey&quot; FOREIGN KEY (&quot;contactId&quot;) REFERENCES &quot;public&quot;.&quot;contacts&quot;(&quot;id&quot;),
  CONSTRAINT &quot;WorkflowAssignationContact_workflowAssignationId_fkey&quot; FOREIGN KEY (&quot;workflowAssignationId&quot;) REFERENCES &quot;wf&quot;.&quot;WorkflowAssignation&quot;(&quot;id&quot;),
  PRIMARY KEY (&quot;workflowAssignationId&quot;,&quot;contactId&quot;));
  </code></pre>
  <p>As I can understand this is a table with two primary keys so for me that means that it will only prevent me from save if the pair (contactId and workflowAssignationId) are equals to other already saved right?</p>
  <p>Well what's happened is that when I try to save with this query:</p>
  <pre><code>INSERT INTO &quot;wf&quot;.&quot;WorkflowAssignationContact&quot; (&quot;workflowAssignationId&quot;, &quot;contactId&quot;, &quot;contactNumber&quot;) VALUES (9, 1887, 'cfs:078286556');
  </code></pre>
  <p>I got this error:</p>
  <p>ERROR:  duplicate key value violates unique constraint &quot;WorkflowAssignationContact_pkey&quot;
  DETAIL:  Key (&quot;workflowAssignationId&quot;, &quot;contactId&quot;)=(9, 1887) already exists.</p>
  <p>The table is completely empty...</p>
  <p>Verified ids 9 exists in the related table and also 1887 is valid Id in the contact tables.</p>
  <p>The sequelize model is this one:</p>
  <pre><code>@Table({timestamps: false, schema: 'wf'})
  export class WorkflowAssignationContact extends Model&lt;WorkflowAssignationContact&gt; {
  
      @PrimaryKey
      @ForeignKey(() =&gt; WorkflowAssignation)
      @Column
      workflowAssignationId: number;
  
      @BelongsTo(() =&gt; WorkflowAssignation)
      workflowAssignation: WorkflowAssignation;
  
      @PrimaryKey
      @ForeignKey(() =&gt; contacts)
      @Column
      contactId: number;
  
      @Column
      contactNumber: string;
  
      @BelongsTo(() =&gt; contacts)
      contact: contacts;
  }
  </code></pre>
  <p>I would really appreciate any help.</p>
  <p><strong>EDIT</strong></p>
  <p>The table is being created with a sequelize migration:</p>
  <pre><code>await queryInterface.createTable(&quot;WorkflowAssignationContact&quot;, {
                  workflowAssignationId: {
                      allowNull  : false,
                      primaryKey : true,
                      type       : Sequelize.INTEGER,
                      references : {
                          model : &quot;WorkflowAssignation&quot;,
                          key   : &quot;id&quot;
                      }
                  },
                  contactId: {
                      allowNull  : false,
                      primaryKey : true,
                      type       : Sequelize.INTEGER,
                      references : {
                          model: {
                              tableName : &quot;contacts&quot;,
                              schema    : &quot;public&quot;
                          },
                          key: &quot;id&quot;
                      }
                  },
                  contactNumber: {
                      allowNull : false,
                      type      : Sequelize.STRING
                  }
              }, { schema: &quot;wf&quot;});
  </code></pre>