Ask Your Question
0

When using flask_sqlalchemy, why do I receive an Assertion Error of "schema is not None" in the has_table assertion?

asked 2022-02-19 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-12-23 18:00:00 +0000

nofretete gravatar image

The Assertion Error "schema is not None" in Flask SQLAlchemy occurs because the function is expecting a schema to be defined in the metadata for the table being queried. If the schema is not defined, the assertion error is thrown. To fix this error, you can add the schema name in the metadata when defining your tables.

For example, you could define a table with the schema name "public" as follows:

from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

class MyTable(db.Model):
    __tablename__ = 'mytable'
    __table_args__ = {'schema': 'public'}

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))

Alternatively, you can define the schema as an argument in the has_table assertion.

For example:

assert engine.has_table('mytable', schema='public')

This checks if the table named "mytable" exists in the schema "public".

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-02-19 11:00:00 +0000

Seen: 10 times

Last updated: Dec 23 '21