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

postgres: Fix inability to create model with known int primary key #613

Closed

Conversation

philband
Copy link

Problem and a partial fix already described in #586

@philband philband requested a review from a team as a code owner December 23, 2020 10:30
Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. Primary keys should not be writeable! If this was changed, it should also be reflected in the other dialects, not just psql.

@philband
Copy link
Author

I don't think this is correct. Primary keys should not be writeable! If this was changed, it should also be reflected in the other dialects, not just psql.

I would argue that as a default, they should be auto-generated. However, there are situations where it is necessary to overwrite this behavior.

Example: I need to import some basic data from a different database that already has existing references and needs matching primary keys for consistency.

Currently, pop silently ignores the primary key set on the import - producing results that can not be intended and to the best of my knowledge, this behavior is not documented anywhere.

@aeneasr
Copy link
Member

aeneasr commented Dec 23, 2020

That might be true - however the submitted code does not behave as you probably expect which is why the test suites are failing. Primary keys should not be writable after the fact. It is true that they could be set before. However, for auto increments, this is a bad idea because the table's ai index is left unchanged, causing future duplicates and other potential issues. If you intend on importing int ai PKs, please do so using SQL instruction sets to avoid common problems of replicating writes instead of ex/importing full schemas.

@philband
Copy link
Author

Okay, that explanation makes sense to me, thank you for clarifying. Closing.

@philband philband closed this Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants