You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
app = Flask(__name__)
db = SQLAlchemy()
db.init_app(app)
class Plan(db.Model):
__table_args__ = (
db.PrimaryKeyConstraint('id', name='pk_plan'),
db.UniqueConstraint('name', name='uq_plan')
)
id = db.Column(db.Integer)
name = db.Column(db.String(50))
with app.app_context():
db.create_all()
When try to generate the table, an error is occurred. The trace back information is something like this:
Traceback (most recent call last):
File "model.py", line 13, in <module>
class Plan(db.Model):
File "/home/zero/study/python_env/for_cl/lib/python3.5/sitepackages/flask_sqlalchemy/__init__.py", line 603, in __init__
DeclarativeMeta.__init__(self, name, bases, d)
File "/home/zero/study/python_env/for_cl/lib/python3.5/sitepackages/sqlalchemy/ext/declarative/api.py", line 64, in __init__
_as_declarative(cls, classname, cls.__dict__)
File "/home/zero/study/python_env/for_cl/lib/python3.5/sitepackages/sqlalchemy/ext/declarative/base.py", line 88, in _as_declarative
_MapperConfig.setup_mapping(cls, classname, dict_)
File "/home/zero/study/python_env/for_cl/lib/python3.5/sitepackages/sqlalchemy/ext/declarative/base.py", line 103, in setup_mapping
cfg_cls(cls_, classname, dict_)
File "/home/zero/study/python_env/for_cl/lib/python3.5/sitepackages/sqlalchemy/ext/declarative/base.py", line 133, in __init__
self._setup_inheritance()
File "/home/zero/study/python_env/for_cl/lib/python3.5/sitepackages/sqlalchemy/ext/declarative/base.py", line 430, in _setup_inheritance
"table-mapped class." % cls
sqlalchemy.exc.InvalidRequestError: Class <class '__main__.Plan'> does not have a __table__ or __tablename__ specified and does not inherit from an existing table-mapped class.
May be it can be enhanced by support the table defined schema like this ?
The text was updated successfully, but these errors were encountered:
Take these code as example:
When try to generate the table, an error is occurred. The trace back information is something like this:
May be it can be enhanced by support the table defined schema like this ?
The text was updated successfully, but these errors were encountered: