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.

docs: add note for auto-increment of primary key

See original GitHub issue

We are using the latest stable version of Hasura v.1.3.1

We have a table with a primary key of type Integer(Auto-Increment):

image

However, when I was writing a script to reset the database to mock data I explicitly passed the primary key IDs in the insert mutation so that the PKs and the FKs to it are always fixed. Now I see that the auto-increment of the primary key does not work and I get Uniqueness violation. duplicate key value violates unique constraint \"location_pkey\" error when I don’t pass the id in the mutation explicitly and even worst I cannot insert a row in the Insert Row tab.

image

image

It seems after I manually set the IDs in the insert mutation now the auto-increment mechanism got confused and doesn’t work anymore. How can I have it again for my tables?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
arashlayeghicommented, Oct 4, 2020

Hey, @Veshu-Arora Thanks for your explanation. I appreciated what you said and realized the root cause of the problem. However, it’s not the solution to our problem. In our use-case, we need to manually insert id for some rows which are mock data. Also, we need that after that we can insert some new rows without id with auto-increment. We cannot simply delete those manually inserted rows to solve this issue.

After all, this is Hasura which is managing PostgreSQL for us, and when we explicitly set the ids in insert mutation it is the responsibility of Hasura to update the maximum id.

1reaction
joshuarobscommented, Mar 2, 2021

Getting this same error. I can’t insert any new rows without this error in the hasura console (and in my app if I call the graphql code). There should be a button that you can press within the hasura console to fix issues like this, to keep things in sync

Read more comments on GitHub >

github_iconTop Results From Across the Web

Defining an Auto Increment Primary Key in SQL Server - Chartio
Learn how to define an auto increment primary key in SQL Server. This data tutorial will explain basic table creation and information around...
Read more >
3.6.9 Using AUTO_INCREMENT - MySQL :: Developer Zone
The AUTO_INCREMENT attribute can be used to generate a unique identity for new rows: CREATE TABLE animals ( id MEDIUMINT NOT NULL AUTO_INCREMENT, ......
Read more >
Google sheet Auto-incrementing ID/Primarykey - Stack Overflow
This code will work no matter where you insert a record, ... entered into cell A1 will auto increment Column A to last...
Read more >
SQL AUTO INCREMENT a Field - W3Schools
Auto-increment allows a unique number to be generated automatically when a new record is inserted into a table. Often this is the primary...
Read more >
Setting up MySQL Auto Increment Primary Key 101 - Hevo Data
When creating a table, assigning a column as the primary key is one of the most common tasks as this key uniquely identifies...
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