SQLite3 OperationalError: Table XYZ has no column named ABC

1,662 views
Skip to first unread message

Matthias

unread,
Apr 20, 2013, 1:02:58 PM4/20/13
to peewe...@googlegroups.com
Hello,

I am new to peewee, so please forgive me if this is a stupid question. I have search on Google and in the peewee cookbook, but found no solution so far. Hopefully you can help me, I guess it's basically an easy thing for you.

So, I have the following models to four of my DB tables:

class games_def(Model):
    id = PrimaryKeyField()
    name = TextField()
    class Meta:
        database = dbmgr.DB

class users_def(Model):
    id = PrimaryKeyField()
    first_name = TextField()
    last_name = TextField()
    class Meta:
        database = dbmgr.DB

class sessions(Model):
    id = PrimaryKeyField()
    game = ForeignKeyField(games_def, related_name = 'sessions')
    user = ForeignKeyField(users_def, related_name = 'sessions')
    comment = TextField()
    class Meta:
        database = dbmgr.DB

class world_states(Model):
    session = ForeignKeyField(sessions)
    time_step = IntegerField()
    world_state = TextField()
    class Meta:
        database = dbmgr.DB


Using these models I connect to an SQLite3 DB via peewee, which works fine.
After the connection has been established I do the following in my main Python code:

models.world_states.create(session = 1, time_step = 1)

However, this gives me the following error:

sqlite3.OperationalError: table world_states has no column named session_id

That is basically correct, the table world_state does indeed not contain such a column.
However, I cannot find any reference to "session_id" in my code at all.

Whe does peewee want to use that "session_id" colum name?
Do I miss something essentially here?

Thanks, Matthias


Charles Leifer

unread,
Apr 20, 2013, 3:24:11 PM4/20/13
to peewe...@googlegroups.com
You can manually specify the column:

class world_states(Model):
    session = ForeignKeyField(sessions, db_column='session')

    time_step = IntegerField()
    world_state = TextField()
    class Meta:
        database = dbmgr.DB


Hope that helps!





--
You received this message because you are subscribed to the Google Groups "peewee-orm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to peewee-orm+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Matthias

unread,
Apr 20, 2013, 4:47:51 PM4/20/13
to peewe...@googlegroups.com
Thank you very much!
Reply all
Reply to author
Forward
0 new messages