New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error Authenticating a User. #222
Comments
The error says the users table does not exist. Have you updated your database migrations? |
I've done |
Yes, that should do it. Look at the output of the command to see if there are any errors. And if you run an update a second time it should say that there's nothing to upgrade, that you are already updated. Any chance the active configuration is different when you do the update versus when you run the server? |
Nope, no errors after upgrade. I think my migration isn't setup properly actually. This is the message I get when running upgrade (any number of times):
Hmm, I don't think the active config is different. I'm just using default in both cases I believe. |
Hmm. Is this code from this repository without any changes? Are you sure you are not calling From your description of the problem, either the server isn't finding the database (so it creates a new empty one), or the database is in the right place, but something is destroying the tables. Look for database files in all the directories you are using, if you find more than one sqlite file, then maybe it is the relative path problem I described above. |
There is only one database file. I don't have I will review the repo and the database chapter and see if I've missed something. Thank you very much for your help! |
You do not need Can't really think of a reason why the server will not find the tables. You may want to try loading and saving users from a shell session as shown in the book. Also, another question. Do you get a successful unit test run? |
Yes, all my unit tests up until chapter 8 have passed. So when loading and saving users through the shell, I get this error: but when I then do: |
Okay. That is consistent with the theory that the database is empty. The object is fine, but loading or saving gives you a "no such table" error. You didn't answer a question I asked above. Do you have any changes from the code in this repository? If you do, add the output of |
I unfortunately didn't pull the repo but started from scratch and have been following along. |
Can I see your |
I did not set any environment variables.
|
The config looks okay. What's the output of |
|
Only those two lines? What files do you have in the |
Yeah. the versions directory is empty as well. |
Okay, we are finally getting somewhere. The problem is that you did not generate a migration for your database. This is the |
I thought I did. I have a migrations directory and everything. |
Oh I see. I ran that command and now I have a new version file. So how often should I run that command? |
You need to generate a migration any time you make a change to your database. After you generate the migration you have to run the I recommend that you reread the Flask-Migrate section of chapter 5 to have a full understanding of things. It isn't always as simple as generating the migration and then running the upgrade, sometimes you need to do more than that. |
Understood. Thank you very much! |
Hello, Miguel I'm working through chapter 8 and I'm getting an error when trying to first authenticate the users. It seems like the tables aren't getting created in my db but when I run
python manage.py shell
andprint u.username
or any other of the attributes I get the correct values returned. Perhaps you know where I'm going wrong? Let me know if I can provide you with any other files. Thanks a lot.OperationalError: (sqlite3.OperationalError) no such table: users [SQL: u'SELECT users.id AS users_id, users.email AS users_email, users.username AS users_username, users.password_hash AS users_password_hash, users.role_id AS users_role_id \nFROM users \nWHERE users.email = ?\n LIMIT ? OFFSET ?'] [parameters: (u'john@example.com', 1, 0)]
The text was updated successfully, but these errors were encountered: