By tommychel
Bonjour,
Tout d’abord merci pour ce tutoriel !
Quand je rentre des données d’utilisateur, j’ai une erreur de ce type :
sqlalchemy.exc.OperationalError sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: user [SQL: SELECT user.id AS user_id, user.email AS user_email, user.password AS user_password, user.name AS user_name FROM user WHERE user.email = ? LIMIT ? OFFSET ?] [parameters: (‘tommychel@hotmail.fr’, 1, 0)] (Background on this error at: http://sqlalche.me/e/13/e3q8)
Après plusieurs heures de recherche, je trouve toujours pas l’erreur et j’ai pourtant bien écrit comme dans le tuto, pouvez vous m’éclaircir à ce sujet ? En attendant je continue de chercher ^^
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
j’ai trouvé, il fallait que je relance dans le terminal l’interpréteur python puis :
from project import db, create_app db.create_all(app=create_app())
Heya,
Based on the error message you’re encountering with SQLAlchemy, it appears that the SQLite database you’re using does not have a table named user. This kind of issue typically occurs under a few different scenarios:
Database Initialization: The most common reason is that the database hasn’t been properly initialized to include the user table. This might happen if the code that creates the database tables has not been executed, or if it executed with errors.
Database Connection Issue: You might be connecting to a different database than you intended, one that doesn’t have the user table. This can occur if the connection string points to a different database file or location.
Schema Mismatch: The table might not exist in the schema for the current environment. Sometimes during development, schema changes might not be properly applied.
1. Check Database Initialization Code Make sure that you have code that initializes the database schema and that it’s being executed before any queries are run. For a Flask application using SQLAlchemy, this usually looks something like this:
from your_application import db
db.create_all()
Ensure that this is run in the correct context and that db is properly configured to point to your SQLite database.
2. Verify Database Connection Check the connection string that SQLAlchemy uses to connect to the SQLite database. It should point to the correct file. This is usually set up in your configuration file or directly in your application setup:
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///path/to/database.db'
Make sure the path is correct and that the specified database file is accessible.
3. Manually Inspect the Database You can manually check if the table exists in the SQLite database by using a tool like DB Browser for SQLite or running a SQL query through a command line tool:
sqlite3 path/to/database.db
And then, within the sqlite3 command-line tool, run:
.tables
This will list all tables in your database. If user is not listed, you know for sure it hasn’t been created.
4. Re-run Migration Scripts If you are using Flask-Migrate (an extension that handles SQLAlchemy database migrations), make sure all migrations are applied:
flask db upgrade
This command applies the migration scripts to your database.
By following these troubleshooting steps, you should be able to identify why the user table is missing from your database and resolve the issue. It’s crucial to ensure that your database schema is correctly initialized and matches the expected state of your application’s code. If the problem persists, you might need to review the tutorial steps or any related documentation again to ensure no steps were missed during setup.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.