Extra `t2` while generating query
q = MsgLog.select().where(MsgLog.master_msg_id.startswith("%s." % chat_id)).order_by(MsgLog.id.desc())

The problem is you're ordering by MsgLog.id but MsgLog.master_msg_id is the primary key and the model (while it has an "id" attribute), does not consider it a valid field.

To fix this, just change your "order_by()" call to order on a field that's defined on the MsgLog model. Or alternatively, you could make "master_msg_id" have "unique=True" instead of being a primary key.
 I think I may make some modifications to Peewee to drop the `id` attribute if a different field is used as the foreign key.
 @coleifer deleting other user's comments just because you don't agree with the technical viewpoint is very uncool.
 The truth is that I removed your comments because they were not constructive, and I was tired of having to defend aspects of my project because you felt entitled to a technical discussion because you happened to disagree with it. When I pointed to you that the things you disagreed with were documented and obviously intentional (via git log), you suggested I was trying to justify, post-hoc, bad design decisions, and was being an irresponsible maintainer. How is that constructive?
 Reopening as I intend to fix. 

# Model

``` python
class MsgLog(Model):
    master_msg_id = CharField(unique=True, primary_key=True)
    text = CharField()
    slave_origin_uid = CharField()
    slave_origin_display_name = CharField(null=True)
    slave_member_uid = CharField(null=True)
    slave_member_display_name = CharField(null=True)
    msg_type = CharField()
    sent_to = CharField()

    class Meta:
        database = SqliteDatabase('data.db')
```
# Query

``` python
chat_id = 1
q = MsgLog.select().where(MsgLog.master_msg_id.startswith("%s." % chat_id)).order_by(MsgLog.id.desc())
print(q)
```
## Expected result

``` sql
SELECT "t1"."master_msg_id", "t1"."text", "t1"."slave_origin_uid", "t1"."slave_origin_display_name", "t1"."slave_member_uid", "t1"."slave_member_display_name", "t1"."msg_type", "t1"."sent_to" FROM "msglog" AS t1 WHERE ("t1"."master_msg_id" LIKE ?) ORDER BY "t1"."id" DESC ['1.%']
```
## Returned result

``` sql
SELECT "t1"."master_msg_id", "t1"."text", "t1"."slave_origin_uid", "t1"."slave_origin_display_name", "t1"."slave_member_uid", "t1"."slave_member_display_name", "t1"."msg_type", "t1"."sent_to" FROM "msglog" AS t1 WHERE ("t1"."master_msg_id" LIKE ?) ORDER BY "t2"."id" DESC ['1.%']
```
