I just want to programatically determine the name of an SQLalchemy model's primary key.
标签:
sqlalchemy
相关问题
- How to compare dates in sqlalchemy?
- Proper way to prevent SQLAlchemy from re-running q
- sqlalchemy: TypeError: unhashable type creating in
- Get rid of double quotation marks with SQLalchemy
- “Inheriting 'Base', which is not a class”
相关文章
- In sqlalchemy, is there a way to sort so that empt
- What is the proper way to insert an object with a
- Sqlalchemy, raw query and parameters
- SQLAlchemy + alembic: create schema migration
- SQLAlchemy - Is there a way to see what is current
- Sum fields in sqlAlchemy
- SQLAlchemy StaleDataError on deleting items insert
- AttributeError: 'UUID' object has no attri
If class is "User", and there is just 1 primary key, do this*:
*Moved from the question.
Assuming the declarative model class is
User
,Or for
Membership
which has a composite primary keyIf using SQLAlchemy version 0.8 or later, you should use the runtime inspection API.
If the model class is
User
and the sole primary key isid
,If the model class is
User
and there are many primary keys,If using SQLAlchemy version less than 0.8, you should use the
class_mapper()
function instead.In this case, the
inspect()
function and theclass_mapper()
function return the same object, but usinginspect()
is more future-proof.