Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#199 KeyError when creating table from MySQL database

closed-fixed
Oleg Broytman
MySQL (29)
5
2006-10-10
2006-09-29
Viktor Ferenczi
No

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`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Create a class from the database:

__connection__='mysql://user:pass@sql_server_host/dbname'
import sqlobject as SO
class Termek(SO.SQLObject):
class sqlmeta:
fromDatabase=True
idName='sorszam'

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__
cls.sqlmeta.addColumnsFromDatabase()
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'

Discussion

  • Oleg Broytman
    Oleg Broytman
    2006-10-10

    Logged In: YES
    user_id=4799

    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
    col.StringCol:

     
  • Oleg Broytman
    Oleg Broytman
    2006-10-10

    • assigned_to: nobody --> phd
    • status: open --> closed-fixed