Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How is it can be - to get error

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

by running 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 win 32 and sqlalchemy 0.8.2 and then I use Python 2.7.4 (default, Sep 26 2013, 03:20:56) [GCC 4.7.3] on linux2 and sqlalchemy 0.7.9

p.s. Also

NameError: name 'Numeric' is not defined

like image 953
user2866992 Avatar asked Oct 10 '13 12:10

user2866992


1 Answers

You need to import that object, you haven't done so in your code.

Simply add Float to your existing from sqlalchemy import line:

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

The same applies to Numeric; you need to explicitly import it, it is not a Python built-in.

like image 55
Martijn Pieters Avatar answered Oct 20 '22 22:10

Martijn Pieters