- changed status to resolved
schematype constraints don't use naming convention if it doesnt include "constraint_name"
Issue #3299
resolved
this is a little limiting. due to #3067, the constraint convention below will not even be consulted:
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
m1 = MetaData(naming_convention={"ck": "ck_%(table_name)s_%(column_0_name)s"})
Base = declarative_base(metadata=m1)
class A(Base):
__tablename__ = 'a'
id = Column(Integer, primary_key=True)
foob = Column(BOOLEAN)
e = create_engine("mysql://scott:tiger@localhost/test", echo=True)
Base.metadata.drop_all(e)
Base.metadata.create_all(e)
this change needs to be made in order for it to be seen:
diff --git a/lib/sqlalchemy/sql/naming.py b/lib/sqlalchemy/sql/naming.py
index 9e57418..21bf05d 100644
--- a/lib/sqlalchemy/sql/naming.py
+++ b/lib/sqlalchemy/sql/naming.py
@@ -114,8 +114,9 @@ def _constraint_name_for_table(const, table):
if isinstance(const.name, conv):
return const.name
elif convention is not None and (
- const.name is None or not isinstance(const.name, conv) and
- "constraint_name" in convention
+ const.name is None or (
+ not isinstance(const.name, conv) or
+ "constraint_name" in convention)
):
return conv(
convention % ConventionDict(const, table,
there's no reason CheckConstraint can't have a .columns collection so that the columns_0_name convention can be useful.
I dont know that we want to change this for 0.9.
Comments (1)
-
reporter - Log in to comment
.CheckConstraint
construct now supports naming conventions that include the token%(column_0_name)s
; the constraint expression is scanned for columns. Additionally, naming conventions for check constraints that don't include the%(constraint_name)s
token will now work for :class:.SchemaType
- generated constraints, such as those of :class:.Boolean
and :class:.Enum
; this stopped working in 0.9.7 due to3067
. fixes#3299→ <<cset 383bb3f70816>>