Error creating a composite index name. #831
Replies: 6 comments
-
Hi - this looks to be an alembic issue, but also I don't have any understanding of what the "error" is. can you please indicate in more concrete terms what it is you refer towards as the "ending", what commands you are running, and very explicitly what it is you are observing? thanks |
Beta Was this translation helpful? Give feedback.
-
I've migrated to alembic. At worst we can migrate it back |
Beta Was this translation helpful? Give feedback.
-
When we create a migration, an ending is added to the name. class Foo(Base):
__tablename__ = 'foo'
__table_args__ = (
CheckConstraint( 'column_a >= 0', name='check_column_a')
)
column_a = Column(
Integer(),
primary_key=True,
autoincrement=False
)
# When use alembic. generate this.
# sa.CheckConstraint('column_a >= 0', name=op.f('check_column_a_ck')) check_column_a_ck -> add tail: _ck For the indexes specified in this way, such an index is added. For example. class Foo(Base):
__tablename__ = 'foo'
column_a = Column(
Integer(),
primary_key=True,
autoincrement=False,
index=True
)
# When use alembic. generate this.
# op.create_index(op.f('foo_column_a_ix'), 'foo', ['foo'], unique=False) foo_column_a_ix -> add tail: _ix But if we do this with arguments using the class Foo(Base):
__tablename__ = 'foo'
__table_args__ = (
Index('foo_column_a_and_column_b', 'column_a', 'column_b')
)
column_a = Column(
Integer(),
primary_key=True,
autoincrement=False
)
column_b = Column(
Integer(),
primary_key=True,
autoincrement=False
)
# When use alembic. generate this.
# op.create_index('foo_column_a_and_column_b', 'foo', ['column_a', 'column_b'], unique=False)
# foo_column_a_and_column_b -> add tail: None |
Beta Was this translation helpful? Give feedback.
-
OK so if I can restate your issue, the naming convention is not being applied to index objects when autogenerate renders the Python code. |
Beta Was this translation helpful? Give feedback.
-
Yes. Thank you) |
Beta Was this translation helpful? Give feedback.
-
OK so what is happening here is your check constraint naming convention includes that it should render with the name of the constraint embedded:
however the constraint you're using for the index does not:
what this means is that because you are giving the Index an explicit name, that supersedes using the naming convention name. Only if the convention contains the so to achieve both names combined with Index, include that in your convention:
|
Beta Was this translation helpful? Give feedback.
-
Describe the bug
When creating a composite index, the ending is not added, but when creating a сheck сonstraint, it is added.
Expected behavior
Adding an ending when creating a composite index.
To Reproduce
Versions.
Additional context
model.py
migrate/env.py
migrate/script.py.mako
alembic.ini
requirements.txt
Have a nice day!
Beta Was this translation helpful? Give feedback.
All reactions