"NameError: the name" Float "is not defined" in sqlalchemy

How can it be - get an error

Traceback (most recent call last):
    File "stx_sql.py", line 19, in<module>
    Column('value', Float),  
NameError: name 'Float' is not defined

running the code

from sqlalchemy import create_engine
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey

engine = create_engine('sqlite:///tttx.sqlite', echo=True)
#engine = create_engine('sqlite:///:memory:', echo=True)

metadata = MetaData()
users_table = Table('users', metadata,
        Column('id', Integer, primary_key=True),
        Column('name', String(50), nullable=False),
        Column('fullname', String(50), nullable=False),
        Column('password', String(70), nullable=False)
    )
points_table = Table('points', metadata,
        Column('id', Integer, primary_key=True),
        Column('name', String(50), unique=True, nullable=False),
        Column('description', String(150)),
        Column('type', Integer),
        Column('value', Float),
        Column('refreshtime', Float),
        Column('lastupdate', Float)
    )
types_table = Table('types', metadata,
        Column('id', Integer, primary_key=True),
        Column('name', String(50), unique=True, nullable=False),
        Column('description', String(150))
    )
metadata.create_all(engine)

then I use Python 2.7.5 (default, May 15, 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on winning 32 and sqlalchemy 0.8.2 and then I use Python 2.7.4 (by default, September 26, 2013, 03:20:56) [GCC 4.7.3] on linux2 and sqlalchemy 0.7.9

ps also

NameError: name 'Numeric' not defined

+4
source share
1 answer

You need to import this object, you did not do this in your code.

Just add Floatto the existing line from sqlalchemy import:

from sqlalchemy import Table, Column, Float, Integer, String, MetaData, ForeignKey

Numeric; , Python.

+9

All Articles