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".
Asked: 2022-02-19 11:00:00 +0000
Seen: 10 times
Last updated: Dec 23 '21