1

I am building my first app with Flask Python micro-framework and I have a problem with committing my models to the database. When I test my User model on the command line, all works well. But when I do a db.session.commit(), I have error 1146 : "Table doesn't exist."

I'm using a MySQL database in local mode and there is no error with login/password Maybe I'm doing it wrong on the configuration or something else. So here is my config application config file

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:admin@localhost/flask_db'
db = SQLAlchemy(app)

from app import views

1 Answer 1

1

The error explains it all-- while you may have the models for your data, you haven't yet created the tables in the database to store and query them. Simply import your models then run db.create_all() to generate the tables and you should be good to go.

It'll be worth you reading the quickstart guide for Flask-SQLAlchemy to get your head around the general flow.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh ! i have done it but the rollbacks may have cancel it that's why ... So, thank you very much, it helped :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.