How to create a table using ORM Declarative class without primary key?
It failed to start if i didn’t make any column the primary_key = True.
How to create a table using ORM Declarative class without primary key? It failed
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.
SQLAlchemy core doesn’t complain about missing primary key, so it’s possible to create such table with
Table(…). But ORM by design requires a way to identify the row corresponding to object, so it’s not possible to use table without primary key in ORM.Why do you need to add this index later? Is it real requirement or an attempt to solve some problem that probably can be solved other way? In case you need composite primary key, it’s possible to define it with either
primary_key=Trueargument in severalColumns or by specifyingPrimaryKeyConstraint(…)in__table_args__.