question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Documentation] Example schema for cockroachdb is not working

See original GitHub issue

Bug description

In the docs with cockroachdb selected (https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/using-prisma-migrate-typescript-cockroachdb)

This is the example schema… which does not work The `autoincrement()` default function is defined only on BigInt fields on CockroachDB. Use sequence() if you want an autoincrementing Int field.

model Post {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  title     String   @db.VarChar(255)
  content   String?
  published Boolean  @default(false)
  author    User     @relation(fields: [authorId], references: [id])
  authorId  Int
}

model Profile {
  id     Int     @id @default(autoincrement())
  bio    String?
  user   User    @relation(fields: [userId], references: [id])
  userId Int     @unique
}

model User {
  id      Int      @id @default(autoincrement())
  email   String   @unique
  name    String?
  posts   Post[]
  profile Profile?
}

I found examples like below, but what is the correct way for a classic autoincrement with cockroachdb ?

model Question {
  id        String   @id @default(cuid())

How to reproduce

Try the example schema with provider = "cockroachdb"

Expected behavior

Working autoincrementing id field. Correct documentation.

Prisma information

Environment & setup

  • OS:
  • Database:
  • Node.js version:

Prisma Version


Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
janpiocommented, Jul 7, 2022

Fundamentally, yes - see https://www.cockroachlabs.com/docs/v21.2/sql-faqs#how-do-i-auto-generate-unique-row-ids-in-cockroachdb and related documenation from CockroachDB.

We are currently re-investigating this and might suggest different defaults for primary key columns (you might notice that our current choice does not necessarily represent best practices as communicated by CockroachDB itself) - but for now this works.

0reactions
erSitztcommented, Jul 9, 2022

I switched back to Int with sequence, that way i did not have to change/cast/convert anything for the other frameworks that ran into the JSON Stringify errors…

I think there should just be a note that there are still issues around in dealing with BigInt and maybe a hint for Int with sequence if someone wants something similar to a classic autoincrement id.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Documentation] Example schema for cockroachdb is not ...
This is the example schema... which does not work The `autoincrement()` default function is defined only on BigInt fields on CockroachDB. Use ...
Read more >
Common Errors and Solutions | CockroachDB Docs
This message indicates a client is trying to connect to a node that is either not running or is not listening on the...
Read more >
Troubleshoot Common Problems | CockroachDB Docs
This page has instructions for handling errors and troubleshooting problems that may arise during application development.
Read more >
Troubleshoot Cluster Setup | CockroachDB Docs
Learn how to troubleshoot issues with starting CockroachDB clusters.
Read more >
Troubleshoot CockroachDB Cloud
Check that you are using the correct cluster and database names. You can find these parameters in the CockroachDB Cloud Console by navigating...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found