Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Unique constraint failed on the fields: (author_id,blog_id) #36

Open
divyenduz opened this issue Mar 11, 2020 · 3 comments
Open

Unique constraint failed on the fields: (author_id,blog_id) #36

divyenduz opened this issue Mar 11, 2020 · 3 comments

Comments

@divyenduz
Copy link

divyenduz commented Mar 11, 2020

Note: most likely a test-utils bug as it is trying to create the same record twice in a relation table.

SQL table: https://github.com/prisma/database-schema-examples/blob/master/postgres/basic-blog/schema.sql#L12-L16

create table if not exists authors_blogs (
  author_id int not null references authors(id) on delete cascade,
  blog_id int not null references blogs(id) on delete cascade,
  unique(author_id, blog_id)
);

Model: https://github.com/prisma/introspection-engine-output/blob/test_utils/postgresql_public_test_utils/basic-blog.log#L16-L21

model authors_blogs {
  author_id authors
  blog_id   blogs

  @@unique([author_id, blog_id], name: "authors_blogs_author_id_blog_id_key")
}

Relevant seed logs:

2020-03-11T13:57:44.561Z prisma-client Prisma Client call:
2020-03-11T13:57:44.561Z prisma-client prisma.authors_blogs.create({
  data: {
    author_id: {
      connect: {
        id: 1
      }
    },
    blog_id: {
      connect: {
        id: 1
      }
    }
  },
  include: {
    author_id: true,
    blog_id: true
  }
})
2020-03-11T13:57:44.561Z prisma-client Generated request:
2020-03-11T13:57:44.561Z prisma-client mutation {
  createOneauthors_blogs(data: {
    author_id: {
      connect: {
        id: 1
      }
    }
    blog_id: {
      connect: {
        id: 1
      }
    }
  }) {
    author_id {
      id
      name
    }
    blog_id {
      id
      name
      viewcount
    }
  }
}

2020-03-11T13:57:45.915Z prisma-client Prisma Client call:
2020-03-11T13:57:45.915Z prisma-client prisma.authors_blogs.create({
  data: {
    author_id: {
      connect: {
        id: 1
      }
    },
    blog_id: {
      connect: {
        id: 1
      }
    }
  },
  include: {
    author_id: true,
    blog_id: true
  }
})
2020-03-11T13:57:45.915Z prisma-client Generated request:
2020-03-11T13:57:45.915Z prisma-client mutation {
  createOneauthors_blogs(data: {
    author_id: {
      connect: {
        id: 1
      }
    }
    blog_id: {
      connect: {
        id: 1
      }
    }
  }) {
    author_id {
      id
      name
    }
    blog_id {
      id
      name
      viewcount
    }
  }
}

Full seed logs: https://github.com/prisma/introspection-engine-output/blob/test_utils/test-utils/results/postgresql_public_test_utils_basic-blog_stderr.log#L151-L193

/home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog
===start client generation===
2020-03-11T13:57:41.296Z prisma-client {
  engineConfig: {
    cwd: '/home/runner/work/introspection-engine-output/introspection-engine-output/postgresql_public_test_utils',
    debug: false,
    datamodelPath: '/home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog/schema.prisma',
    prismaPath: undefined,
    datasources: [],
    generator: {
      name: 'client',
      provider: 'prisma-client-js',
      output: '/home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog',
      binaryTargets: [],
      config: {}
    },
    showColors: false,
    logLevel: undefined,
    logQueries: undefined,
    env: {},
    flags: []
  }
}
===end client generation===
===start seed===
2020-03-11T13:57:41.401Z prisma-client Prisma Client call:
2020-03-11T13:57:41.403Z prisma-client prisma.authors.create({
  data: {
    name: 'ofosid'
  }
})
2020-03-11T13:57:41.403Z prisma-client Generated request:
2020-03-11T13:57:41.403Z prisma-client mutation {
  createOneauthors(data: {
    name: "ofosid"
  }) {
    id
    name
  }
}

2020-03-11T13:57:41.406Z engine {
  PRISMA_DML_PATH: '/home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog/schema.prisma',
  PORT: '46725',
  RUST_BACKTRACE: '1',
  RUST_LOG: 'info',
  OVERWRITE_DATASOURCES: '[]'
}
2020-03-11T13:57:41.406Z engine {
  cwd: '/home/runner/work/introspection-engine-output/introspection-engine-output/postgresql_public_test_utils'
}
2020-03-11T13:57:41.408Z getos { version: 'OpenSSL 1.1.1d  10 Sep 2019\n' }
2020-03-11T13:57:41.409Z getos { ls: '' }
2020-03-11T13:57:41.415Z getos { platform: 'linux', libssl: '1.1.x' }
2020-03-11T13:57:41.415Z plusX Execution permissions of /home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog/runtime/query-engine-debian-openssl-1.1.x are fine
2020-03-11T13:57:41.416Z engine { flags: [ '--enable-raw-queries' ] }
2020-03-11T13:57:41.435Z engine stderr Printing to stderr for debugging
2020-03-11T13:57:41.436Z engine stderr Listening on 127.0.0.1:46725
2020-03-11T13:57:41.437Z engine stdout {
  timestamp: 'Mar 11 13:57:41.437',
  level: 'INFO',
  target: 'quaint::pooled',
  fields: { message: 'Starting a postgresql pool with 5 connections.' }
}
2020-03-11T13:57:41.442Z engine stdout {
  timestamp: 'Mar 11 13:57:41.442',
  level: 'INFO',
  target: 'prisma::server',
  fields: {
    message: 'Started http server on 127.0.0.1:46725',
    'log.target': 'prisma::server',
    'log.module_path': 'prisma::server',
    'log.file': 'query-engine/prisma/src/server.rs',
    'log.line': 95
  }
}
2020-03-11T13:57:42.657Z prisma-client Prisma Client call:
2020-03-11T13:57:42.657Z prisma-client prisma.authors.create({
  data: {
    name: 'daej'
  }
})
2020-03-11T13:57:42.657Z prisma-client Generated request:
2020-03-11T13:57:42.657Z prisma-client mutation {
  createOneauthors(data: {
    name: "daej"
  }) {
    id
    name
  }
}

2020-03-11T13:57:43.303Z prisma-client Prisma Client call:
2020-03-11T13:57:43.303Z prisma-client prisma.blogs.create({
  data: {
    name: 'wocu',
    viewcount: 888
  }
})
2020-03-11T13:57:43.303Z prisma-client Generated request:
2020-03-11T13:57:43.303Z prisma-client mutation {
  createOneblogs(data: {
    name: "wocu"
    viewcount: 888
  }) {
    id
    name
    viewcount
  }
}

2020-03-11T13:57:43.931Z prisma-client Prisma Client call:
2020-03-11T13:57:43.931Z prisma-client prisma.blogs.create({
  data: {
    name: 'gafgohrak',
    viewcount: -1908
  }
})
2020-03-11T13:57:43.931Z prisma-client Generated request:
2020-03-11T13:57:43.931Z prisma-client mutation {
  createOneblogs(data: {
    name: "gafgohrak"
    viewcount: -1908
  }) {
    id
    name
    viewcount
  }
}

2020-03-11T13:57:44.561Z prisma-client Prisma Client call:
2020-03-11T13:57:44.561Z prisma-client prisma.authors_blogs.create({
  data: {
    author_id: {
      connect: {
        id: 1
      }
    },
    blog_id: {
      connect: {
        id: 1
      }
    }
  },
  include: {
    author_id: true,
    blog_id: true
  }
})
2020-03-11T13:57:44.561Z prisma-client Generated request:
2020-03-11T13:57:44.561Z prisma-client mutation {
  createOneauthors_blogs(data: {
    author_id: {
      connect: {
        id: 1
      }
    }
    blog_id: {
      connect: {
        id: 1
      }
    }
  }) {
    author_id {
      id
      name
    }
    blog_id {
      id
      name
      viewcount
    }
  }
}

2020-03-11T13:57:45.915Z prisma-client Prisma Client call:
2020-03-11T13:57:45.915Z prisma-client prisma.authors_blogs.create({
  data: {
    author_id: {
      connect: {
        id: 1
      }
    },
    blog_id: {
      connect: {
        id: 1
      }
    }
  },
  include: {
    author_id: true,
    blog_id: true
  }
})
2020-03-11T13:57:45.915Z prisma-client Generated request:
2020-03-11T13:57:45.915Z prisma-client mutation {
  createOneauthors_blogs(data: {
    author_id: {
      connect: {
        id: 1
      }
    }
    blog_id: {
      connect: {
        id: 1
      }
    }
  }) {
    author_id {
      id
      name
    }
    blog_id {
      id
      name
      viewcount
    }
  }
}

2020-03-11T13:57:46.726Z printStack callsite Error
    at Object.s [as authors_blogs] (/home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog/runtime/index.js:1:44468)
    at Object.n.<computed> [as create] (/home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog/runtime/index.js:1:46094)
    at /home/runner/work/introspection-engine-output/prisma-test-utils/src/static/seed.ts:935:45
    at Generator.next (<anonymous>)
    at /home/runner/work/introspection-engine-output/prisma-test-utils/dist/static/seed.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/home/runner/work/introspection-engine-output/prisma-test-utils/dist/static/seed.js:4:12)
    at iterate (/home/runner/work/introspection-engine-output/prisma-test-utils/dist/static/seed.js:642:24)
    at /home/runner/work/introspection-engine-output/prisma-test-utils/src/static/seed.ts:958:30
    at Generator.next (<anonymous>)
PrismaClientKnownRequestError: 
Invalid `prisma.authors_blogs.create()` invocation in
/home/runner/work/introspection-engine-output/prisma-test-utils/src/static/seed.ts:935:45

Unique constraint failed on the fields: (`author_id`,`blog_id`)
    at PrismaClientFetcher.request (/home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog/runtime/index.js:1:47071)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  code: 'P2002',
  meta: { target: [ 'author_id', 'blog_id' ] }
}
===end seed===
2020-03-11T13:57:46.729Z engine Stopping Prisma engine
2020-03-11T13:57:46.815Z getos { version: 'OpenSSL 1.1.1d  10 Sep 2019\n' }
2020-03-11T13:57:46.815Z getos { ls: '' }
2020-03-11T13:57:46.816Z getos { platform: 'linux', libssl: '1.1.x' }
Terms
Privacy
Security
Status
Help
Contact GitHub
Pricing
API
Training
Blog
About

@divyenduz divyenduz added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. comment: possibly test-utils problem datebase: PostgreSQL labels Mar 11, 2020
@janpio janpio removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. labels Mar 11, 2020
@janpio
Copy link
Contributor

janpio commented Mar 11, 2020

This indeed looks like a test-utils problem - it creates the entries in both tables successfully, but then tried to insert data in the relation table that can not work.

@jpbidal
Copy link

jpbidal commented Apr 4, 2021

Hello, I've the same problem, on create it runs ok, but on update upsert throws Unique constraint failed on the fields: (col1,col2,col3)

@janpio
Copy link
Contributor

janpio commented Apr 4, 2021

This project is currently not maintained, so it is expected that stuff does not work right now unfortunately.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants