I just want to programatically determine the name of an SQLalchemy model’s primary key.
I just want to programatically determine the name of an SQLalchemy model’s primary key.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If using SQLAlchemy version 0.8 or later, you should use the runtime inspection API.
If the model class is
Userand the sole primary key isid,If the model class is
Userand 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.