#199 KeyError when creating table from MySQL database

MySQL (29)

Use Python 2.4.3 (MSI installer) and SQLObject 0.7.1 installed with python setup.py install from tar.gz on WinXP. Connect to MySQL 4.1.11 server on another machine and create the table in a database (read on below):

-- phpMyAdmin SQL Dump
-- version 2.6.2-Debian-3sarge1
-- http://www.phpmyadmin.net
-- Hoszt: localhost
-- Létrehozás ideje: 2006. Szept 29. 12:53
-- Szerver verzió: 4.1.11
-- PHP Verzió: 4.3.10-16
CREATE TABLE `termek` (
`sorszam` int(11) NOT NULL auto_increment,
`rogzitette` int(11) NOT NULL default '0',
`felvitel` datetime NOT NULL default '0000-00-00 00:00:00',
`kategoria` int(11) NOT NULL default '0',
`nev` varchar(200) NOT NULL default '',
`prnev` varchar(200) NOT NULL default '',
`prnevetikett` varchar(200) default NULL,
`kod` int(11) default NULL,
`szjszam` varchar(20) default NULL,
`vamszam` varchar(16) default NULL,
`gyarto` int(11) default NULL,
`tomeg` float NOT NULL default '0',
`nettobeszerzesiar` decimal(14,2) default NULL,
`nettoegysegar` decimal(14,2) default NULL,
`afakulcs` decimal(5,2) NOT NULL default '20.00',
`ajandek` enum('Y','N') NOT NULL default 'N',
`alaptermek` int(11) default NULL,
`allapot` enum('aktiv','inaktiv','torolt') NOT NULL default 'aktiv',
PRIMARY KEY (`sorszam`),
KEY `rogzitette` (`rogzitette`),
KEY `nev` (`nev`),
KEY `ajandek` (`ajandek`),
KEY `kod` (`kod`),
KEY `gyarto` (`gyarto`),
KEY `kategoria` (`kategoria`)

Create a class from the database:

import sqlobject as SO
class Termek(SO.SQLObject):
class sqlmeta:

You should get the following exception:

Traceback (most recent call last):
File "rendeles-import.py", line 25, in ?
class Termek(SO.SQLObject):
File "c:\python24\lib\site-packages\SQLObject-0.7.1-py2.4.egg\sqlobject\declarative.py", line 109, in __new__
cls.__classinit__(cls, new_attrs)
File "c:\python24\lib\site-packages\SQLObject-0.7.1-py2.4.egg\sqlobject\main.py", line 777, in __classinit__
File "c:\python24\lib\site-packages\SQLObject-0.7.1-py2.4.egg\sqlobject\main.py", line 422, in addColumnsFromDatabase
for columnDef in conn.columnsFromSchema(sqlmeta.table, soClass):
File "c:\python24\lib\site-packages\SQLObject-0.7.1-py2.4.egg\sqlobject\mysql\mysqlconnection.py", line 153, in columnsFromSchema
if self.kw['use_unicode'] and colClass is col.StringCol:
KeyError: 'use_unicode'


  • Oleg Broytman

    Oleg Broytman - 2006-10-10

    Logged In: YES

    Fixed in the SVN in the revision 1997 in hte trunk, r1998 in
    the 0.7 branch. Meanwhile replace the offending line with:

    if self.kw.get('use_unicode') and colClass is

  • Oleg Broytman

    Oleg Broytman - 2006-10-10
    • assigned_to: nobody --> phd
    • status: open --> closed-fixed

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks