Flask not creating Sqlite database via Slqalchemy

Asked

Viewed 280 times

2

Good afternoon to all!

No way my code is creating the database via SQL Alchemy, follow the code snippet.

    from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLAlchemy_DATABASE_URI'] = 'sqlite:///database.db'

db = SQLAlchemy(app)

class Person(db.Model):
    __tablename__ = 'cliente'

    _id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    nome = db.Column(db.String)
    telefone = db.Column(db.String)
    cpf = db.Column(db.String)
    email = db.Column(db.String)

    def __init__(self, nome, telefone, cpf, email):
        self.nome = nome
        self.telefone = telefone
        self.cpf = cpf
        self.email = email

db.create_all()

I’ve even tried creating the database manually and just connecting to it, but it still doesn’t work. I’m following a sequence of videos to learn, however, it’s a little old, I’m for some time trying to solve this and I can’t.

My operating system is Ubuntu, already tried to set the path via realpath, also does not work.

Someone’s been through it and managed to solve it?

  • 1

    Try to use SQLALCHEMY_DATABASE_URI instead of SQLAlchemy_DATABASE_URI and see what happens. In this case the difference is that everything is capitalized.

  • It worked, thank you very much!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.