python - Sql Alchemy What is wrong? -


i got tutorial

http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html

when compile got error message

the debugged program raised exception unhandled nameerror "name 'boundmetadata' not defined" 

i use latest sqlalchemy .

how fixed this?

after read modified own latest version sqlalchemy:

from sqlalchemy import * engine = create_engine('mysql://root:mypassword@localhost/mysql') metadata = metadata() users = table('users', metadata,     column('user_id', integer, primary_key=true),     column('name', string(40)),     column('age', integer),     column('password', string), ) metadata.create_all(engine)  = users.insert() i.execute(name='mary', age=30, password='secret') i.execute({'name': 'john', 'age': 42},           {'name': 'susan', 'age': 57},           {'name': 'carl', 'age': 33}) s = users.select() rs = s.execute() row = rs.fetchone() print 'id:', row[0] print 'name:', row['name'] print 'age:', row.age print 'password:', row[users.c.password] row in rs:     print row.name, 'is', row.age, 'years old 

it raise error

 raise exc.dbapierror.instance(statement, parameters, e, connection_invalidated=is_disconnect) sqlalchemy.exc.programmingerror: (programmingerror) (1064, "you have error in sql syntax; check manual corresponds mysql server version right syntax use near ' \n\tprimary key (user_id)\n)' @ line 5") '\ncreate table users (\n\tuser_id integer not null auto_increment, \n\tname varchar(40), \n\tage integer, \n\tpassword varchar, \n\tprimary key (user_id)\n)\n\n' () 

this tutorial sqlalchemy version 0.2. since actual version 0.5.7, i'd tutorial severely outdated.

try official 1 instead.


edit:

now have different question. should've asked question instead of editing one.

your problem that

column('password', string), 

doesn't specify size column.

try

column('password', string(20)), 

instead.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

gdi+ - WxWidgets draw a bitmap with opacity -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -