-1
class KtOwnerAddressMaster(db.Model):
__tablename__ = 'kt_owner_address_master'
ADDRESS_ID = db.Column(Integer, primary_key=True)
STREET1 = db.Column(String(1024), nullable=False)
STREET2 = db.Column(String(1024))
ZIP = db.Column(String(15))
CITY_NAME = db.Column(String(200))
STATE = db.Column(String(200))
COUNTRY = db.Column(String(200))
ADDR_EXT_ID = db.Column(String(50), nullable=False, unique=True)
CREATED_ON = db.Column(DateTime, nullable=False)
UPDATED_ON = db.Column(DateTime)
def __init__(self, **kwargs):
super(KtOwnerAddressMaster, self).__init__(**kwargs)
return
class KtOwnerAddressMap(KtOwnerAddressMaster):
__tablename__ = 'kt_owner_address_map'
ADDRESS_ID =db.Column(ForeignKey(u'kt_owner_address_master.ADDRESS_ID'), primary_key=True)
CURRENT_ADDR = db.Column(SmallInteger, nullable=False, server_default=text("'0'"))
FRIENDLY_NAME = db.Column(String(100))
OWNER_ID = db.Column(ForeignKey(u'kt_owner_master.OWNER_ID'), nullable=False, index=True)
kt_owner_master = relationship(u'KtOwnerMaster')
def __init__(self, **kwargs):
super(KtOwnerAddressMap, self).__init__(**kwargs)
return
在我的觀點我做以下幾點:SQL鍊金術會話調用不同的表
ad_object=KtOwnerAddressMaster(STREET1=street1,
STREET2=street2,
ZIP=zipcode,
ADDR_EXT_ID=addr_ext_id,
CREATED_ON=datetime.now().strftime("%Y:%m:%d %H:%M:%S"),
UPDATED_ON=datetime.now().strftime("%Y:%m:%d %H:%M:%S"),
CITY_NAME =city_name,
STATE=state,
COUNTRY=country)
db.session.add(ad_object)
db.session.commit()
addr_obj=db.session.query(KtOwnerAddressMaster).filter_by(ADDR_EXT_ID=addr_ext_id).with_entities(KtOwnerAddressMaster.ADDRESS_ID).first()
address_id=int(addr_obj[0])
現在我想一個地址映射添加到所有者地址映射表。
add_object=KtOwnerAddressMap(ADDRESS_ID=address_id,
CURRENT_ADDR="current_addr",
FRIENDLY_NAME="friendly_name",
OWNER_ID=owner_id)
db.session.add(add_object)
#The error appears on the below commit
db.session.commit()
我能夠看到正在填充數據庫中的地址。但我無法插入所有者來解決表中的映射問題。 它給了我下面的錯誤: (_mysql_exceptions.OperationalError)(1048, 「列STREET1」不能爲空「)[SQL:u'INSERT INTO kt_owner_address_master(ADDRESS_ID
,STREET1
,STREET2
,ZIP
,CITY_NAME
,STATE
,COUNTRY
, ADDR_EXT_ID
,CREATED_ON
,UPDATED_ON
)VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'] [參數:(51,None,None,沒有,沒有,沒有,沒有,沒有,沒有)]
您的幫助將不勝感激。