1.异常情况如下:
- 使用flask_sqlalchemy中,设置数据库模型类的时候报的错误
- 模型类去继承某个抽象类的时候
File "D:\TestSoftware\Python2.7.13\lib\site-packages\sqlalchemy\orm\decl_base.py", line 628, in _produce_column_copies
column_copies[obj] = copy_ = obj._copy()
File "D:\TestSoftware\Python2.7.13\lib\site-packages\sqlalchemy\sql\schema.py", line 1911, in _copy
return self._schema_item_copy(c)
File "D:\TestSoftware\Python2.7.13\lib\site-packages\sqlalchemy\sql\schema.py", line 153, in _schema_item_copy
schema_item.info = self.info.copy()
AttributeError: 'str' object has no attribute 'copy'
2.代码情况如下:
class AbstractAutoTestData(BaseModule):
__abstract__ = True
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
auto_case = db.Column(db.Integer)
case_id = db.Column(db.Text, info='用例id')
case_name = db.Column(db.Text, nullable=False, info='用例描述')
class AutoTestDataXT(AbstractAutoTestData):
__tablename__ = 'auto_test_data_xt'
start_time = db.Column(db.Text)
3.解决方法:
class AbstractAutoTestData(BaseModule):
__abstract__ = True
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
auto_case = db.Column(db.Integer)
case_id = db.Column(db.Text)
case_name = db.Column(db.Text, nullable=False)
- 在设置为抽象类的类中,每个字段不能使用info去描述字段的含义,否者就报如上错误
- 可以使用nullable = Fasle & server_default=db.FetchedValue() 等字段属性设置,但info万万不行!!!
|