Comments (3)
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. 🙂
from tortoise-orm.
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)
from tortoise-orm.
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. :)
from tortoise-orm.
Related Issues (20)
- Tortoise ORM tutorial missing context? HOT 4
- Tortoise orm F expression
- Docs request: if `pk` will be unique HOT 1
- Updating config at runtime
- Meta indexes are not created safely
- mssql named instance port number
- Add support for composite primary keys and foreign keys
- Corrupt sql generated when bulk_create method is configured with on_conflict parameter
- https://tortoise.github.io/0.19.1 gives 404
- model relationship bugged HOT 8
- why are there three files for one database? HOT 1
- auto_now not working HOT 2
- Field 'DatetimeField' has error when I use '__year' or '__month'. report this:" 'int' object has no attribute 'utcoffset' " HOT 1
- Tortoise ORM integration with FastAPI lifespan ('NoneType' object is not iterable) HOT 1
- update(balance=Wallet.balance+1) how to do this? HOT 1
- Req: concurrent use of multiple databases
- model.update_or_create KeyError HOT 3
- Bug: Pydantic 2.7 broke `pydantic_model_creator` HOT 7
- Occasionally during high-frequency queries, there may be differences between SQL statements and query results, leading to KeyError errors. Additionally, Command Out of Sync errors may also be reported during transactions
- QuerySet.count(): IndexError: list index out of range HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tortoise-orm.