Skip to content
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

mysql default clause doesnt have a dispatcher #736

Closed
zzzeek opened this issue Sep 11, 2020 · 1 comment
Closed

mysql default clause doesnt have a dispatcher #736

zzzeek opened this issue Sep 11, 2020 · 1 comment
Labels
bug Something isn't working mysql op directives

Comments

@zzzeek
Copy link
Member

zzzeek commented Sep 11, 2020

moved from sqlalchemy/sqlalchemy#5574

# Insert code here
from sqlalchemy import Column
from sqlalchemy import Float
from sqlalchemy import Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine

#url = "sqlite:////tmp/sqlite.db"  ## different error
url = "mysql://test:test@localhost/test"

# first let's create the old table

BasePrep = declarative_base()
class TestPrep(BasePrep):
    __tablename__ = "test123"
    id = Column(Integer, primary_key=True)
    label_x = Column(Float, nullable=False, server_default="0")
    label_y = Column(Float, nullable=False, server_default="0")
enginePrep = create_engine(url)
BasePrep.metadata.create_all(enginePrep)

# this is the new one

Base = declarative_base()
class Test(Base):
    __tablename__ = "test123"
    id = Column(Integer, primary_key=True)
    label_x = Column(Float, default=0)  # dies
    label_y = Column(Float, nullable=True)  # also dies

# now try to migrate this

from alembic.runtime.migration import MigrationContext
from alembic.autogenerate import api
from alembic.operations.base import Operations

engine = create_engine(url)

session = Session(engine)
ctx = MigrationContext(dialect=session.bind.dialect, connection=session.connection(), opts={})
res = api.produce_migrations(ctx,Test.__table__.metadata)
ops = Operations(ctx, ctx.impl)

# If there's an Alembic method to do this without looping, I haven't found it.
def all_ops(op):
    if hasattr(op,"ops"):
        for o in op.ops:
            yield from all_ops(o)
    else:
        yield op
for op in all_ops(res.upgrade_ops):
    print(type(op),vars(op))
    ops.invoke(op)
@zzzeek zzzeek added requires triage New issue that requires categorization bug Something isn't working mysql op directives and removed requires triage New issue that requires categorization labels Sep 11, 2020
@sqla-tester
Copy link
Collaborator

Mike Bayer has proposed a fix for this issue in the master branch:

Use regular renderer for MySQL server default https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/2221

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mysql op directives
Projects
None yet
Development

No branches or pull requests

2 participants