python3----异常处理----AttributeError: ‘str‘ object has no attribute ‘copy‘

文章目录

1.异常情况如下:

  1. 使用flask_sqlalchemy中,设置数据库模型类的时候报的错误
  2. 模型类去继承某个抽象类的时候

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='用例描述')


# 对应表格auto_test_data_xt
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)					 # info='用例id' 
    case_name = db.Column(db.Text, nullable=False)   # info='用例描述'

  • 在设置为抽象类的类中,每个字段不能使用info去描述字段的含义,否者就报如上错误
  • 可以使用nullable = Fasle & server_default=db.FetchedValue() 等字段属性设置,但info万万不行!!!
上一篇:json+数据库


下一篇:使用Nexus配置Maven私有仓库