我正在用原子运行sqlalchemy代码,并由于网络开发的新手而收到了我不理解的错误。 同样从终端运行时,它也会显示相同的错误。 代码如下:
root@KS:~/Desktop/hello_files# python database_setup.py
Traceback (most recent call last):
File "database_setup.py", line 15, in <module>
class Restaurant(Base):
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/api.py", line 75, in __init__
_as_declarative(cls, classname, cls.__dict__)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/base.py", line 130, in _as_declarative
_MapperConfig.setup_mapping(cls, classname, dict_)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/base.py", line 158, in setup_mapping
cfg_cls(cls_, classname, dict_)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/base.py", line 188, in __init__
self._setup_inheritance()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/base.py", line 583, in _setup_inheritance
"table-mapped class." % cls
sqlalchemy.exc.InvalidRequestError: Class <class '__main__.Restaurant'> does not have a __table__ or __tablename__ specified and does not inherit from an existing table-mapped class.
答案 0 :(得分:0)
您需要在__tablename__
类上指定一个Restaurant
。也许像__tablename__ = 'restaurants'