On Aug 26, 2010, at 11:42 AM, Chris Withers wrote:

> Hi All,
> 
> For the following model:
> 
> class Header(Base):
>    __tablename__ = 'header'
>    id = Column(Integer, primary_key=True)
>    message_id = Column(Integer,ForeignKey('message.id'))
>    name = Column(String(50))
>    value = Column(Text(255))
> 
> sqlalchemy-migrate's SchemaDiff tool against the table freshly created in 
> MySQL gives:
> 
> Schema diffs:
>  tables with differences: header
>    header with different declaration of columns in database: 
> [(Column('value', Text(length=255, convert_unicode=False, 
> assert_unicode=None, unicode_error=None, _warn_on_bytestring=False), 
> table=<header>), Column(u'value', TINYTEXT(), table=<header>), 'value 
> TEXT(255)', 'value TINYTEXT')]
> 
> The schema diff stuff basically does the following to get the database column 
> declaration with SA 0.6+:
> 
>    from sqlalchemy.ext import compiler
>    from sqlalchemy.schema import DDLElement
>    class DefineColumn(DDLElement):
>        def __init__(self, col):
>            self.col = col
> 
>    @compiler.compiles(DefineColumn)
>    def compile(elem, compiler, **kw):
>        return compiler.get_column_specification(elem.col)
> 
>    def get_column_specification(col):
>        return str(DefineColumn(col).compile(dialect=self.conn.dialect))
> 
> How can it be changed so that the column reflected from the DB and the column 
> calculated from the model end up being the same?

if schemas are being diffed, types can be compared "generically" using "type 
affinity".  This is described at:

http://www.sqlalchemy.org/trac/wiki/06Migration#ReflectionReturnsDialect-SpecificTypes

You could also take a reflected table and force all of its types down to the 
"generic" ones using a hack like column.type.__class__ = 
column.type._type_affinity to change the class of each type down to its "basic" 
version.     But if a diff is all that's needed they should be using that.

(FYI alembic will have no schema diff feature its not something I buy into much)

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to