0
Engine = create_engine("mysql+mysqldb://blah-blah-blah", encoding="utf-8")
Session = sessionmaker(bind = Engine)
ses = Session()
Meta = MetaData(bind = Engine, reflect = True)
PersonTable = Meta.tables["person"]

class Person(object):
   pass

mapper(Person, PersonTable)
APerson = Person("1111", "2222", "1.01.1980")
ses.add(APerson)
ses.commit()

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 '%s, %s, %s)' at line 1") b'INSERT INTO person (Name, OriginalName, DoB) VALUES (%s, %s, %s)' ('1111', '2222', '25.01.1980')

What is the %s? What do I wrong?

Python 3.1 SQLAlchemy 0.6.5 MySQL 5.1 Windows 7 Ultimate

Thank you.

Evgeni
  • 1
  • 1
  • its a C-style print thing, where each %s is supposed to sub for the string values '1111', '222' and '25.01.1980' respectively. I don't know sqlalchemy in order to help you fix this – jon_darkstar Nov 18 '10 at 14:11
  • here is a similar question although more recent, hopefully it will have a useful answer: http://stackoverflow.com/questions/14732533/pyramid-python3-sqlalchemy-and-mysql – Sheena Feb 06 '13 at 16:33

2 Answers2

0

You sqlalchemy commit is trying to issue an insert query that is not compatible with the schema. near '%s, %s, %s)' means your trying to insert invalid data. I can only speculate that it is because the date format - this is not the proper mysql date format YYYY-MM-DD.

vonPetrushev
  • 5,457
  • 6
  • 39
  • 51
  • I removed columb "DoB", but it did not help. The same error. CREATE TABLE `Person`( `ID` INT(11) NOT NULL AUTO_INCREMENT, `Name` VARCHAR(255) NOT NULL, `OriginalName` VARCHAR(255), PRIMARY KEY (`ID`) ) ENGINE=InnoDB; – Evgeni Nov 19 '10 at 05:59
0

I migrated back to Python 2.7. Now it works fine.

Evgeni
  • 1
  • 1