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

Generic PK field that references real PK field #36

Closed
abondar opened this issue Jul 25, 2018 · 3 comments · Fixed by #122
Closed

Generic PK field that references real PK field #36

abondar opened this issue Jul 25, 2018 · 3 comments · Fixed by #122
Labels
Next Release Issues tagged for next Major release target Urgent

Comments

@abondar
Copy link
Member

abondar commented Jul 25, 2018

Currently tortoise can work normally if your PK is int field named id. It should instead work with pk field like in django, that references real PK field that can have various types and names

@grigi grigi mentioned this issue Jul 25, 2018
72 tasks
@grigi grigi added the Next Release Issues tagged for next Major release target label Aug 5, 2018
@monospacedmagic
Copy link

This issue is indeed very important as it prevents people from normalizing their databases in a sane way. This would not be too much of an issue if we could just easily migrate the database structure once this issue is fixed and we changed our database structure, however, migration is also not yet implemented and seems to be a far more complex issue than this.

While you're at it, you could add support for composite primary keys as well. The lack of that feature already made it difficult to properly normalize tables in Django, so it would be especially nice to have it here. 🙂

@grigi
Copy link
Member

grigi commented Jan 28, 2019

Composite primary keys is a touchy subject, but they have their use cases.

I for one, was actually thankful that Django imposed the non-composite rule on me, and it forced me to come up with a better design. But there is still cases where a composite key is the best solution.

The other thing is, that depending on the database (e.g. MySQL), having a autonumber as the primary key is essentially free, as it you have a rowid if you want it or not. Which means that non-autonumber primary keys have a significant disadvantage out of the gate.

But let that not discourage us. This is something that I really wanted to get done, and even labeled it as a pre-requisite for v1.0 (Which is the first planned stable release, with all the formalized baggage that implies)

@grigi grigi added the Urgent label Jan 28, 2019
@monospacedmagic
Copy link

Thank you!

In my particular use case, I am building a library, and a UserGroup's name is already a unique identifier, so it would make sense to make it the primary key. In another use case, I want to set the foreign keys of a through table for a ManyToManyField as primary keys because the pair of them uniquely identifies a database tuple already, no need for an ID. On top of the no need for an ID, it's also easier for library users to create objects of that through model because they can know the values of the two foreign primary keys, but they cannot know the auto-generated IDs.

I hope that makes sense and clarifies why I want/need this as much as I do. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Next Release Issues tagged for next Major release target Urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants