0
I am developing a small application in Flask and I am using the extensions Flask-Sqlalchemy, Flask-Migrate and Flask-Script to manage my migrations in the database, follow the configuration of my application.
# -*- coding: utf-8 -*-
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
from flask_login import LoginManager
from flask_mail import Mail
import coverage
import os
import unittest
# Aplicativo
app = Flask(__name__)
# Configurações
app.config.from_object(os.environ['APP_SETTINGS'])
# Database
db = SQLAlchemy(app)
# Migrações
migrate = Migrate(app, db)
# Manager
manager = Manager(app)
manager.add_command('db', MigrateCommand)
# Autenticação
login = LoginManager(app)
login.login_view = 'login'
# Mail
mail = Mail(app)
# Importações
from app import routes
from users import views, models
# Blueprints
app.register_blueprint(views.bp)
I start the database with flask db init, create migration with flask db migrate and update the database with flask db upgrade the problem is that when trying to use the database I get the following error:
sqlalchemy.exc.OperationalError
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: users [SQL: 'INSERT INTO users (username, password_hash, email) VALUES (?, ?, ?)'] [parameters: ('thiago', 'pbkdf2:sha256:50000$OINivJRi$d81223e55b8b4ef150c49c251c2007b756efa5cef51ed8bbdde66c263e20f2cf', 'tth*****@gmail.com')] (Background on this error at: http://sqlalche.me/e/e3q8)
When I then log into a flask shell session and do a db.create_all() database function, but is it really necessary to do it manually? If yes in which file should I do this?
The problem is that the table was not created before you tried to enter the data. You checked whether the first migration generated by
flask-migrateare creating these tables? How are some migrations?– Renan Gomes