0
我对数据库中表更改的时间与SQLAlchemy的声明模型中定义的类对象相匹配感到困惑。SQLAlchemy表未在数据库中反映出来
举例来说,我有一个表commands
这些领域
Command.__table__
Table('commands', MetaData(bind=None), Column('id', Integer(), table=<commands>, primary_key=True, nullable=False), Column('user_id', Integer(), ForeignKey('users.id'), table=<commands>), Column('command_title', String(length=50), table=<commands>), Column('command_desc', String(length=100), table=<commands>), Column('time_added', DateTime(), table=<commands>), Column('time_updated', DateTime(), table=<commands>), Column('favorite', Boolean(), table=<commands>), schema=None)
然而,当我尝试在我的数据库中添加一个新行,SQL会抱怨。我认为这是因为我刚添加了列favorite
并且它尚未反映在数据库中。
错误:
OperationalError: (OperationalError) table commands has no column named favorite u'INSERT INTO commands (user_id, command_title, command_desc, time_added, time_updated, favorite) VALUES (?, ?, ?, ?, ?, ?)' (2, u'HI', None, None, None, 1)
请描述您在哪里以及如何添加新栏目?你是否更新了数据库模式以反映这种变化? – vvladymyrov 2013-05-02 18:02:45
我有一个名为models.py的文件,其中我有一个从Base继承的类,并有一个类变量“favorite = Column(Boolean())”。这是您所指的模式还是您指的是实际数据库中的模式,这可能不反映最新的模型? – user1431282 2013-05-02 18:33:40