Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn on create if Primary Key / ID is out of the default sequence #333

Closed
elaine-jackson opened this issue May 14, 2019 · 3 comments
Closed

Comments

@elaine-jackson
Copy link

I ran into a bug (https://gitlab.lunorian.is/snippets/177) caused by the ID in my database being out of sequence as I copied stuff over from my development environment database onto the server (which probably wasn't the best way to migrate in retrospect). That said I later encountered a bug preventing me from adding versions since the ID it was trying to use was taken. It gave me a difficult to understand error message (01:06:15 Granite | (ERROR) Save Exception: duplicate key value violates unique constraint "versions_pkey") the other thing I know for sure is its trying to save with a key that's already taken. Ideally it would both tell me the exact id its trying to use, and then ask me is the id out of sequence or something so I as a developer know what to look for.

@Blacksmoke16
Copy link
Contributor

This is a bit outside the scope of Granite. It's not really Granite's responsibility to make sure the underlying database was setup properly, or resolve issues related to it.

@drujensen
Copy link
Member

@nsuchy with that said, looks like the auto increment value is not properly set on the new db. Consider setting it to the max(id) + 1. Here is how you would do that for MySQL:
ALTER TABLE tablename AUTO_INCREMENT = 1234

@Blacksmoke16
Copy link
Contributor

Blacksmoke16 commented May 14, 2019

Sorry @drujensen, this issue was a followup to an issue he had that was resolved in the amber chat on Gitter. Issue was a DB migration he did, didn't include the sequence for the table from dev to prod. Thus the PKs were overlapping, causing the error.

Reference: https://gitter.im/amberframework/amber?at=5cdafadbe7f42160fa8b16f4

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

No branches or pull requests

3 participants