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
render func.XYZ constructs correctly in defaults #64
Comments
ElGans (@delegans) wrote: It works when I write alembic migration script like this:
|
Changes by Michael Bayer (@zzzeek):
|
Michael Bayer (@zzzeek) wrote: This is the correct behavior. http://docs.sqlalchemy.org/en/rel_0_7/core/schema.html?highlight=column#sqlalchemy.schema.Column server_default – A FetchedValue instance, str, Unicode or text() construct representing the DDL DEFAULT value for the column. String types will be emitted as-is, surrounded by single quotes: Column('x', Text, server_default="val") x TEXT DEFAULT 'val' A text() expression will be rendered as-is, without quotes: Column('y', DateTime, server_default=text('NOW()'))0 y DATETIME DEFAULT NOW() Strings and text() will be converted into a DefaultClause object upon initialization. |
Michael Bayer (@zzzeek) wrote: so you want to use |
ElGans (@delegans) wrote: Forgot to specify this issue is only for 'revision -auto'. |
ElGans (@delegans) wrote: --autogenerate does not generate migration script correctly when I set column server_default like this db.func.now() |
ElGans (@delegans) wrote: but sqlalchemy does ddl correctly for this one |
Michael Bayer (@zzzeek) wrote: DB backend matters quite a bit here. However, it's documented that server_default can't work fully - we don't get back consistent enough information from the database to know what should be quoted and not, and how. Here's the docs for that: http://alembic.readthedocs.org/en/latest/tutorial.html#auto-generating-migrations Autogenerate can optionally detect: Change of server default. This will occur if you set compare_server_default=True on EnvironmentContext.configure(). This feature works well for simple cases but cannot always produce accurate results. The Postgresql backend will actually invoke the “detected” and “metadata” values against the database to determine equivalence. The feature is off by default so that it can be tested on the target schema first. Like type comparison, it can also be customized by passing a callable; see the function’s documentation for details. This possibly can be worked around to some degree by using a column_reflect event that changes the type to have text() surrounding it, for specific strings. |
Carl Meyer (@carljm) wrote: It seems to me that this bug report was misunderstood and closed incorrectly. I don't care about detection of changes to a column's Specifically, it generates What you actually want is Is it really not possible for alembic to generate the right thing here, for a newly-created column? |
Michael Bayer (@zzzeek) wrote: yes the original user did not describe this clearly. |
Changes by Michael Bayer (@zzzeek):
|
Changes by Michael Bayer (@zzzeek):
|
Changes by Michael Bayer (@zzzeek):
|
Changes by Michael Bayer (@zzzeek):
|
Changes by Michael Bayer (@zzzeek):
|
Migrated issue, originally created by ElGans (@delegans)
(description modified from the original)
renders:
instead of
The text was updated successfully, but these errors were encountered: