Ho ottenuto il tutorialSql Alchemy Cosa c'è di sbagliato?
Quando compilo ricevuto il messaggio di errore
The debugged program raised the exception unhandled NameError
"name 'BoundMetaData' is not defined"
Sono utilizzare l'ultima SQLAlchemy.
Come posso risolvere questo problema?
Dopo leggere questo ho modificato per la mia per la versione più recente SQLAlchemy:
from sqlalchemy import *
engine = create_engine('mysql://root:[email protected]/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)
i = 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]
for row in rs:
print row.name, 'is', row.age, 'years old
E alzare errore
raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect)
sqlalchemy.exc.ProgrammingError: (ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' \n\tPRIMARY KEY (user_id)\n)' at 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'()
@Nosklo. Grazie mille. È quello che voglio. – kn3l
Questo link "ufficiale" è rotto – dlchambers
Penso che questo sia il link ufficiale al momento: http://docs.sqlalchemy.org/en/latest/orm/tutorial.html –