Issue: Uppercase table names not parsed correctly
Author: ThomDietrich
State: closed
Created: 2013-06-07 12:24:57

Hey there,
I'm fresh to peewee and am trying to access existing mysql tables of mine.
It seems to me as peewee has problems with uppercase letters in table names...

My system: Ubuntu 12.04.2, mysql 14.14, python 2.7, peewee 2.1.2

```
  class ratelist(MySQLModel):
    prefix = CharField(primary_key=True)
    name = CharField()

  class trafficRemaining(MySQLModel):
    customerID = IntegerField(primary_key=True)
    abc = IntegerField()


   print ratelist.get()
   <__main__.ratelist object at 0x8a1a56c>

   print trafficRemaining.get()
     File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2299, in get
    return sq.get()
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1602, in get
    return clone.execute().next()
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1637, in execute
    self._qr = ResultWrapper(self.model_class, self._execute(), query_meta)
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1395, in _execute
    return self.database.execute_sql(sql, params, self.require_commit)
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1805, in execute_sql
    res = cursor.execute(sql, params or ())
  File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1146, "Table 'mydatabase.trafficremaining' doesn't exist")
```

As you can see, "ratelist" is accessable but "trafficRemaining" is converted to lowercase and not found by mysql.

Thanks for your work! Greetings


You can explicitly set the database table name to use:

class trafficRemaining(MySQLModel):
    customerID = IntegerField(primary_key=True)
    abc = IntegerField()

```
class Meta:
    db_table = 'trafficRemaining'
```

On Fri, Jun 7, 2013 at 7:24 AM, ThomDietrich notifications@github.comwrote:

> Hey there,
> I'm fresh to peewee and am trying to access existing mysql tables of mine.
> It seems to me as peewee has problems with uppercase letters in table
> names...
> 
> My system: Ubuntu 12.04.2, mysql 14.14, python 2.7, peewee 2.1.2
> 
>   class ratelist(MySQLModel):
>     prefix = CharField(primary_key=True)
>     name = CharField()
> 
>   class trafficRemaining(MySQLModel):
>     customerID = IntegerField(primary_key=True)
>     abc = IntegerField()
> 
>    print ratelist.get()
>    <**main**.ratelist object at 0x8a1a56c>
> 
>    print trafficRemaining.get()
>      File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2299, in get
>     return sq.get()
>   File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1602, in get
>     return clone.execute().next()
>   File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1637, in execute
>     self._qr = ResultWrapper(self.model_class, self._execute(), query_meta)
>   File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1395, in _execute
>     return self.database.execute_sql(sql, params, self.require_commit)
>   File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1805, in execute_sql
>     res = cursor.execute(sql, params or ())
>   File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
>     self.errorhandler(self, exc, value)
>   File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
>     raise errorclass, errorvalue
> _mysql_exceptions.ProgrammingError: (1146, "Table 'mydatabase.trafficremaining' doesn't exist")
> 
> As you can see, "ratelist" is accessable but "trafficRemaining" is
> converted to lowercase and not found by mysql.
> 
> Thanks for your work! Greetings
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/issues/201
> .


Hey, thanks for your response.
I think you understood me wrong. The database name is set correctly (in my case "mydatabase") and works with table "ratelist" but not with "trafficRemaining"...
In my previous message, pay attention to the last errorline: "Table 'mydatabase.trafficremaining' doesn't exist" - this seems to me like a uppercase/lowercase problem...
-Thomas


Try the code. It sets the db_table not the database.
On Jun 10, 2013 7:43 AM, "ThomDietrich" notifications@github.com wrote:

> Hey, thanks for your response.
> I think you understood me wrong. The database name is set correctly (in my
> case "mydatabase") and works with table "ratelist" but not with
> "trafficRemaining"...
> In my previous message, pay attention to the last errorline: "Table
> 'mydatabase.trafficremaining' doesn't exist" - this seems to me like a
> uppercase/lowercase problem...
> -Thomas
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/issues/201#issuecomment-19196087
> .


Ah now I see what you did there. Thanks! It works.
However, this does seem like a workaround but not like a the real solution and should be fixed, right?

Best wishes and thanks for your work, Thomas


> However, this does seem like a workaround but not like a the real solution and should be fixed, right?

I'm not sure what you mean "the real solution".  Did you use `pwiz` to auto-generate your models and it did not create the correct models?