I'm currently working on pset7, cs50 finance. I just implemented the buy method, and when I went to login on my site, I encountered a key error, pointing to 'id' in the following line in the login method:

session["user_id"] = rows[0]["id"]

Strangely enough, login was implemented by staff, so I don't know what could possibly be wrong with it. The same error appears when I try to register, only with a similar line in my register method. My website was working fine before I implemented buy. My only fear is that I might have altered an index in users when creating my portfolio table; I tried to make an index in portfolio by the name of username, unknowing that an index was also named username in users. I dismissed the error message, but I realize now that I still might have unknowingly changed the index in users. If this is indeed the problem, how could I change the index in users back? If not, what else might I be doing wrong?

1 Answer 1


That error from the supplied login means there is no column named id in the users table. It doesn't seem to have anything to do with indexes. Assuming the rest of the table is intact, you might try adding the column back in phpliteadmin. It is INTEGER, AUTOINCREMENT, PRIMARY KEY.

  • Yes, I noticed that too. I decided to redownload the pset in another folder and compare the two databases when I noticed that the first database was missing the id row. I have no idea how that happened, but no harm done I guess. Anyway, thanks for the help!
    – Jason_V
    Commented Jul 11, 2017 at 16:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .