Float() parameters don't enforce proper database column definition with MySQL

Issue #2258 resolved
Former user created an issue

I'm using flask-sqlalchemy and its developer said that the following is a SQLAlchemy issue:

If I do something like: lat = db.Column(db.Float(precision=16, scale=6), nullable=False)

and then I use MySQL's SHOW CREATE TABLE tablename .. I get the following: lat float NOT NULL,

Which shows that the precision and scale parameters are ineffective.

Comments (5)

  1. Mike Bayer repo owner

    Also can't reproduce exactly your description - "precision" is correctly interpreted by the MySQL dialect when specified on the base Float type:

    from sqlalchemy import Float, Table, MetaData, Column
    from sqlalchemy.schema import CreateTable
    
    f = Float(precision=5, scale=10)
    
    from sqlalchemy.dialects import mysql
    
    print f.compile(dialect=mysql.dialect())
    
    t = Table('foo', MetaData(), Column('x', Float(precision=5, scale=10)))
    
    print CreateTable(t)
    print CreateTable(t).compile(dialect=mysql.dialect())
    

    output:

    FLOAT(5)
    
    CREATE TABLE foo (
        x FLOAT
    )
    
    
    
    CREATE TABLE foo (
        x FLOAT(5)
    )
    
  2. Log in to comment