On Mon, Jul 22, 2019, at 6:01 PM, Jonathan Vanasco wrote:
> Mike-
>
> I'm not sure if this is a bug or docs incompatibility issue, and I know
> metadata may be going away soon... but I'm leaning towards a bug.
>
> I was setting up a test suite for a Pyramid plugin, and used the Alembic
> naming conventions (https://alembic.sqlalchemy.org/en/latest/naming.html) as
> Pyramid references them too.
>
> Using the sqlite driver, this generates a fatal exception:
>
> sqlalchemy.exc.InvalidRequestError: Naming convention including
> %(constraint_name)s token requires that constraint is explicitly named.
>
> Tracing things around, it seems due to `sqlalchemy.Boolean` creating a
> constraint by default. Switching Boolean to Unicode immediately fixes this;
> passing in `create_constraint=False` works too.
well that's what it's being told to do, booleans create a CHECK constraint, the
naming convention is "ck_%(table_name)s_%(constraint_name)s", and
"constraint_name" is not generated. I know this is a bit of a catch but I'm not
sure what other choice it should be making.
likely , the "create_constraint" flag should default to False for booleans and
enums. I think it was a mistake to default these to true, I think people
usually don't care.
>
>
>
> # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> -
> # Standard imports
>
>
> import sqlalchemy
> import sqlalchemy.orm
>
>
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy import Boolean, Integer, Column, Unicode, ForeignKey, String
>
>
>
>
> NAMING_CONVENTION = {
> "ix": 'ix_%(column_0_label)s',
> "uq": "uq_%(table_name)s_%(column_0_name)s",
> "ck": "ck_%(table_name)s_%(constraint_name)s",
> "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
> "pk": "pk_%(table_name)s"
> }
> _metadata = sqlalchemy.MetaData(naming_convention=NAMING_CONVENTION)
>
>
> Base = declarative_base(metadata=_metadata)
>
>
> # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> -
> # Define some models that inherit from Base
>
>
> class Foo(Base):
> __tablename__ = 'foo'
> id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
> status_id = sqlalchemy.Column(sqlalchemy.Boolean, nullable=True,
> default=None)
> # the following works:
> # status_id = sqlalchemy.Column(sqlalchemy.Unicode, nullable=True,
> default=None)
> # the following works:
> # status_id = sqlalchemy.Column(sqlalchemy.Boolean(create_constraint=True),
> nullable=True, default=None)
>
>
>
>
>
> # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> -
> # set the engine
>
>
> engine = sqlalchemy.create_engine('sqlite:///:memory:', echo=True)
> Base.metadata.create_all(engine)
>
>
>
>
>
>
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/ac139582-d690-48c1-ac18-cf1536f37750%40googlegroups.com
>
> <https://groups.google.com/d/msgid/sqlalchemy/ac139582-d690-48c1-ac18-cf1536f37750%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/671e0557-b894-4130-8fb1-b87bbe7aa917%40www.fastmail.com.