Assuming here your constraints are already defined in Python and we are not talking about using reflection, we're talking about the CHECK constraint objects you've already built. If they are defined for a Table then they would be in table.constraints. If you have them on the Column then it's true they might only be in column.constraints in that case. If you're defining them in either place then you'd need to look in either place. It might be best to go with all table-bound CHECK constraints as I'm not sure it's as flexible to do add/drop with the column-level ones. At the very least, constraints need to have an explicit name in order to support ADD/DROP.

Alembic's docs get into this a bit here: http://alembic.zzzcomputing.com/en/latest/naming.html where it talks about the "naming convention" feature of SQLAlchemy that may or may not be of use here.





On 11/18/2016 04:43 PM, Jonathan Rogers wrote:
I have a Declarative-instrumented class with several constraints, some
defined at the table level and some on a column. AFAICT, all the
constraints are configured correctly because they are rendered correctly
by CreateTable() when called with the class's Table instance. In order
to import some data into my carefully designed model, I need to drop
some constraints, then recreate them NOT VALID. I want to use the
existing Table instance to execute SQL rather than typing duplicate SQL
manually. However, I'm having trouble introspecting the Table instance
to find a specific CheckConstraint defined on a specific column. The
Table instance's "constraints" property does not contain the constraint
I need. I can find a CheckConstraint instance in the column's
"constraints" property but it's not bound to a Table so I can't just
pass it to DropConstraint(). What is the proper way to get a
CheckConstraint instance defined on a column that I can pass to
DropConstraint() and AddConstraint()?

--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and
Verifiable Example. See http://stackoverflow.com/help/mcve for a full
description.
---
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to