编程语言
首页 > 编程语言> > python3----异常处理----AttributeError: ‘str‘ object has no attribute ‘copy‘

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,__,no,Column,True,db,----,copy,AttributeError
来源: https://blog.csdn.net/chenmozhe22/article/details/123133696