-
-
Notifications
You must be signed in to change notification settings - Fork 268
ValueError: Constraint must have a name
in alembic 1.10.0
#1195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Seems related to 714b744 |
The error occurs here: alembic/alembic/operations/batch.py Lines 665 to 667 in cd7b1a9
|
diff --git a/mlflow/store/db_migrations/versions/cfd24bdc0731_update_run_status_constraint_with_killed.py b/mlflow/store/db_migrations/versions/cfd24bdc0731_update_run_status_constraint_with_killed.py
index beb02a2d3..89a207576 100644
--- a/mlflow/store/db_migrations/versions/cfd24bdc0731_update_run_status_constraint_with_killed.py
+++ b/mlflow/store/db_migrations/versions/cfd24bdc0731_update_run_status_constraint_with_killed.py
@@ -60,6 +60,7 @@ def upgrade():
*new_run_statuses,
create_constraint=True,
native_enum=False,
+ name="status",
),
existing_type=Enum(
*old_run_statuses, fixed the error. |
this seems a regression. Let's keep open for now, until we investigate |
@CaselIT Got it! |
thanks for reporting |
thanks for reporting. This looks like a regression. set |
@ts-accessio just to confirm, you are using sqlite what sqlalchemy version? |
SQLAlchemy==1.3.24 |
Mike Bayer has proposed a fix for this issue in the main branch: distinguish between string contraint name and defined https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/4491 |
Hello, I have same problems with alembic==1.10.1 (or latest)
migration file:
code:
DB Browser for SQLite Version 3.12.2 |
For this time I solve by changing migration file:
But in db it looks :
instead of
|
same issue for 1.11.1 fixed using @kitty7c6 solution |
I'm not even creating a constraint and still running into this issue for
yields
|
Can confirm for |
same error for version modify according to method from @kitty7c6 works:
|
I have the same issue with the latest version |
Issue still exists with 1.15.1 |
folks, I dont have any information on this "bug" such as a model that reproduces, so juts posting "I have this issue" is not helping anything be done with this. I need a reproducer, in this case it most likely would be in the form of 1. an existing schema I can run into SQLite and 2. a series of batch statements that nonetheless fail to recreate the table, coupled with the fact that 3. you also need to take special steps with batch and certain constraint operations |
@zzzeek I was under the impression that the context of the problem was clear. My bad. I created a sample project + steps on how to reproduce the issue. See https://github.com/sn0opy/alembic-constraint-issue I'm unsure if and how the mentioned docs about foreign key contraints in sqlite may help here as others have pointed out, they aren't creating any foreign keyt contraints on purpose. |
thanks for that. you dont have the issue. you have to assign a name to your unique constraint that you are adding (using sqlmodel's unique=True thing). See https://alembic.sqlalchemy.org/en/latest/naming.html for background: import uuid
from sqlmodel import Field, SQLModel
from sqlalchemy import MetaData
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"
}
SQLModel.metadata = MetaData(naming_convention=convention)
class User(SQLModel, table=True):
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
email_address: str = Field(unique=True)
external_id: str = Field(unique=True)
created_at: int run revision and we get
revision succeeds |
im closing this issue because I think people are hitting known complexities of "batch" migrations and they need to discuss them separately |
folks, if you are getting "constraint must have a name", please open a new discussion and show us your migrations since it's likely not a bug. thanks |
Describe the bug
ValueError: Constraint must have a name
in alembic 1.10.0.Expected behavior
Migration succeeds.
To Reproduce
Please try to provide a Minimal, Complete, and Verifiable example, with the migration script and/or the SQLAlchemy tables or models involved.
See also Reporting Bugs on the website.
I'm trying to create a minimal reproducer now, but the migration script that caused the error looks like this:
Error
Versions.
Additional context
The migration script works fine in alembic 1.9.4.
Have a nice day!
The text was updated successfully, but these errors were encountered: