无法在SQLAlchemy上更改类

时间:2015-06-04 02:05:35

标签: python sqlalchemy

您好我正在尝试更改SQLAlchemy中的一个类,因为它给了我一个错误,错误是:

File "<string>", line 2, in __init__
File "C:\Python34\lib\site-packages\sqlalchemy\orm\instrumentation.py", line 324, in _new_state_if_none
    state = self._state_constructor(instance, self)
  File "C:\Python34\lib\site-packages\sqlalchemy\util\langhelpers.py", line 725, in __get__
    obj.__dict__[self.__name__] = result = self.fget(obj)
  File "C:\Python34\lib\site-packages\sqlalchemy\orm\instrumentation.py", line 158, in _state_constructor
    self.dispatch.first_init(self, self.class_)
  File "C:\Python34\lib\site-packages\sqlalchemy\event\attr.py", line 260, in __call__
    fn(*args, **kw)
  File "C:\Python34\lib\site-packages\sqlalchemy\orm\mapper.py", line 2693, in _event_on_first_init
    configure_mappers()
  File "C:\Python34\lib\site-packages\sqlalchemy\orm\mapper.py", line 2589, in configure_mappers
    mapper._post_configure_properties()
  File "C:\Python34\lib\site-packages\sqlalchemy\orm\mapper.py", line 1694, in _post_configure_properties
    prop.init()
  File "C:\Python34\lib\site-packages\sqlalchemy\orm\interfaces.py", line 144, in init
    self.do_init()
  File "C:\Python34\lib\site-packages\sqlalchemy\orm\relationships.py", line 1549, in do_init
    self._process_dependent_arguments()
  File "C:\Python34\lib\site-packages\sqlalchemy\orm\relationships.py", line 1605, in _process_dependent_arguments
    self.target = self.mapper.mapped_table
  File "C:\Python34\lib\site-packages\sqlalchemy\util\langhelpers.py", line 725, in __get__
    obj.__dict__[self.__name__] = result = self.fget(obj)
  File "C:\Python34\lib\site-packages\sqlalchemy\orm\relationships.py", line 1535, in mapper
    % (self.key, type(argument)))
sqlalchemy.exc.ArgumentError: relationship 'prod_comm_rel' expects a class or a mapper argument (received: <class 'sqlalchemy.sql.schema.Column'>)

但是它永远不会改变错误,这是我的班级:

class Product(Base):
    __tablename__="xxxxxx_reg"

    __table_args__ = {"useexisting": True}

    id = Column("id",BIGINT, primary_key=True)
    name = Column("_name",Text, nullable=False)
    code = Column("code", BIGINT, unique=True)
    status = Column("status",BIGINT, ForeignKey(Status.code),nullable=False)
    description = Column("description",Text, nullable=False)
    avatar = Column("avatar", Text, nullable=False)
    type = Column("_type",BIGINT, ForeignKey(Type.id),nullable=False)
    price = Column("price",Numeric(20,2),nullable=False)
    costs = Column("costs",Numeric(20,2),default=0.00)
    commCode = Column("commerce", BIGINT, ForeignKey(Commerce.code), nullable=False)

    #Relation
    prod_status_rel = relationship(Status, backref=backref("Product"))
    prod_type_rel = relationship(Type, backref=backref("Product"))
    prod_comm_rel = relationship(Commerce, backref=backref("Product"))

    def __repr__(self):
        return "<Product(id='%s', name='%s', status='%s', description='%s', " \
               "type='%s', price='%s', costs='%s', code='%s',commerce='%s')>"%(self.id, self.name,
                                                                        self.status,self.description,
                                                  self.type, self.price, self.costs, self.code, self.commCode)

    metadata = MetaData()


    product_tbl = Table(__tablename__, metadata,id,name,status,description, type,price, costs, code, commCode)

    engine = conection().conORM()
    metadata.create_all(engine)

如何修复此代码,因为我进行了更改,当我单独运行该类时,问题是当我尝试使用代码的其他部分运行它时

0 个答案:

没有答案