Re: [sqlalchemy] Table CheckConstraint() limit?
On Mon, 7 May 2018, Mike Bayer wrote: the CHECK constraint only accepts a single SQL expression. Above, it looks like you re looking to add a CHECK constraint for each expression: __table_args__ = ( CheckConstraint(wtemp_unit.in_(['C', 'F'])), CheckConstraint(atemp_unit.in_(['C', 'F'])), # etc. ) Mike, Yes, that's what I need to do. I'll add each separately. Thanks, Rich -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] Table CheckConstraint() limit?
On Mon, May 7, 2018 at 11:31 AM, Rich Shepardwrote: > The module, models.py, has five classes. Each has table constraints: three > have a single table constraint, one has two table constraints, and one has > seven table constraints. SA seems to reject more than four table > constraints. > > With the last three commented out, there's no error: > > __table_args__ = ( > CheckConstraint( > wtemp_unit.in_(['C', 'F']), > atemp_unit.in_(['C', 'F']), > vel_unit.in_(['ft/sec','m/sec']), > disc_unit.in_(['cfs','cms']), > #depth_unit.in_(['in', 'ft', 'cm', 'm']), > #width_unit.in_(['in', 'ft', 'cm', 'm']), > #slope_unit.in_(['deg', '%']) > ), > ) the CHECK constraint only accepts a single SQL expression. Above, it looks like you re looking to add a CHECK constraint for each expression: __table_args__ = ( CheckConstraint(wtemp_unit.in_(['C', 'F'])), CheckConstraint(atemp_unit.in_(['C', 'F'])), # etc. ) > > But, when I allow the fifth there's a problem: > > $ ./openEDMS.py Traceback (most recent call last): > File "/usr/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line > 682, in __getattr__ > return getattr(self.comparator, key) > AttributeError: 'Comparator' object has no attribute 'constraints' > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "./openEDMS.py", line 18, in > import models > File "/home/rshepard/development/openEDMS/models.py", line 144, in > > class Physical(Base): > File "/home/rshepard/development/openEDMS/models.py", line 178, in > Physical > depth_unit.in_(['in', 'ft', 'cm', 'm']), > File "/usr/lib/python3.6/site-packages/sqlalchemy/sql/schema.py", line > 2791, in __init__ > self._set_parent_with_dispatch(table) > File "/usr/lib/python3.6/site-packages/sqlalchemy/sql/base.py", line 431, > in _set_parent_with_dispatch > self._set_parent(parent) > File "/usr/lib/python3.6/site-packages/sqlalchemy/sql/schema.py", line > 2708, in _set_parent > Constraint._set_parent(self, table) > File "/usr/lib/python3.6/site-packages/sqlalchemy/sql/schema.py", line > 2553, in _set_parent > parent.constraints.add(self) > File "/usr/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line > 688, in __getattr__ > key) > AttributeError: Neither 'BinaryExpression' object nor 'Comparator' object > has an attribute 'constraints' > > I've looked in the docs and searched the web without finding mention of a > limit. Looking at the list of constraints I'm not seeing syntatic > differences in the latter three. Please show me what I've missed. > > Rich > > -- > 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 sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] Table CheckConstraint() limit?
The module, models.py, has five classes. Each has table constraints: three have a single table constraint, one has two table constraints, and one has seven table constraints. SA seems to reject more than four table constraints. With the last three commented out, there's no error: __table_args__ = ( CheckConstraint( wtemp_unit.in_(['C', 'F']), atemp_unit.in_(['C', 'F']), vel_unit.in_(['ft/sec','m/sec']), disc_unit.in_(['cfs','cms']), #depth_unit.in_(['in', 'ft', 'cm', 'm']), #width_unit.in_(['in', 'ft', 'cm', 'm']), #slope_unit.in_(['deg', '%']) ), ) But, when I allow the fifth there's a problem: $ ./openEDMS.py Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line 682, in __getattr__ return getattr(self.comparator, key) AttributeError: 'Comparator' object has no attribute 'constraints' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "./openEDMS.py", line 18, in import models File "/home/rshepard/development/openEDMS/models.py", line 144, in class Physical(Base): File "/home/rshepard/development/openEDMS/models.py", line 178, in Physical depth_unit.in_(['in', 'ft', 'cm', 'm']), File "/usr/lib/python3.6/site-packages/sqlalchemy/sql/schema.py", line 2791, in __init__ self._set_parent_with_dispatch(table) File "/usr/lib/python3.6/site-packages/sqlalchemy/sql/base.py", line 431, in _set_parent_with_dispatch self._set_parent(parent) File "/usr/lib/python3.6/site-packages/sqlalchemy/sql/schema.py", line 2708, in _set_parent Constraint._set_parent(self, table) File "/usr/lib/python3.6/site-packages/sqlalchemy/sql/schema.py", line 2553, in _set_parent parent.constraints.add(self) File "/usr/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line 688, in __getattr__ key) AttributeError: Neither 'BinaryExpression' object nor 'Comparator' object has an attribute 'constraints' I've looked in the docs and searched the web without finding mention of a limit. Looking at the list of constraints I'm not seeing syntatic differences in the latter three. Please show me what I've missed. Rich -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.