当前位置: 首页 > news >正文

网站开发是前端吗营销策划推广公司

网站开发是前端吗,营销策划推广公司,设计师必看的10个网站,手机版企业网站phpsqlacehmy one to one ------detial to descript 关于uselist的使用。如果你使用orm直接创建表关系,实际上在数据库中是可以创建成多对多的关系,如果加上uselistFalse 你会发现你的orm只能查询出来一个,如果不要这个参数orm查询的就是多个,一对多的…

sqlacehmy  one to one    ------detial  to descript

 关于uselist的使用。如果你使用orm直接创建表关系,实际上在数据库中是可以创建成多对多的关系,如果加上uselist=False 你会发现你的orm只能查询出来一个,如果不要这个参数orm查询的就是多个,一对多的关系。数据库级别如果也要限制可以自行建立唯一键进行约束。

总结就是:sqlacehmy One to One 是orm级别限制

sqlacehmy 简单创建实例展示:

from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Integer, String, DateTime ​ ​Base = declarative_base()engine = create_engine('mysql+pymysql://root:123456@localhost:3306/test?charset=utf8', echo=True) ​ ​ class Worker(Base):   # 表名   __tablename__ = 'worker'   id = Column(Integer, primary_key=True)   name = Column(String(50), unique=True)   age = Column(Integer)   birth = Column(DateTime)   part_name = Column(String(50)) ​ ​ # 创建数据表Base.metadata.create_all(engine)

该方法引入declarative_base模块,生成其对象Base,再创建一个类Worker。一般情况下,数据表名和类名是一致的。tablename用于定义数据表的名称,可以忽略,忽略时默认定义类名为数据表名。然后创建字段id、name、age、birth、part_name,最后使用Base.metadata.create_all(engine)在数据库中创建对应的数据表

数据表的删除

删除数据表的时候,一定要先删除设有外键的数据表,也就是先删除part,然后才能删除worker,两者之间涉及外键,这是在数据库中删除数据表的规则。对于两种不同方式创建的数据表,删除语句也不一样。

Base.metadata.drop_all(engine)

part.drop(bind=engine)

part.drop(bind=engine) Base.metadata.drop_all(engine)

sqlachemy +orm + create table代码


from sqlalchemy import Column, String, create_engine, Integer, Text
from sqlalchemy.orm import sessionmaker,declarative_base
import time# 创建对象的基类:
Base = declarative_base()# 定义User对象:
class User(Base):# 表的名字:__tablename__ = 'wokers'# 表的结构:id = Column(Integer, autoincrement=True, primary_key=True, unique=True, nullable=False)name = Column(String(50), nullable=False)sex = Column(String(4), nullable=False)nation = Column(String(20), nullable=False)birth = Column(String(8), nullable=False)id_address = Column(Text, nullable=False)id_number = Column(String(18), nullable=False)creater = Column(String(32))create_time = Column(String(20), nullable=False)updater = Column(String(32))update_time = Column(String(20), nullable=False, default=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),onupdate=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))comment = Column(String(200))# 初始化数据库连接:
engine = create_engine('postgresql://postgres:name@pwd:port/dbname')  # 用户名:密码@localhost:端口/数据库名Base.metadata.create_all(bind=engine)

可级联删除的写法实例 

class Parent(Base):__tablename__ = "parent"id = Column(Integer, primary_key=True)class Child(Base):__tablename__ = "child"id = Column(Integer, primary_key=True)parentid = Column(Integer, ForeignKey(Parent.id, ondelete='cascade'))parent = relationship(Parent, backref="children")

sqlachemy 比较好用的orm介绍链接:https://www.cnblogs.com/DragonFire/p/10166527.html

sqlachemy的级联删除:

https://www.cnblogs.com/ShanCe/p/15381412.html

除了以上例子还列举一下创建多对多关系实例

class UserModel(BaseModel):__tablename__ = "system_user"__table_args__ = ({'comment': '用户表'})username = Column(String(150), nullable=False, comment="用户名")password = Column(String(128), nullable=False, comment="密码")name = Column(String(40), nullable=False, comment="姓名")mobile = Column(String(20), nullable=True, comment="手机号")email = Column(String(255), nullable=True, comment="邮箱")gender = Column(Integer, default=1, nullable=False, comment="性别")avatar = Column(String(255), nullable=True, comment="头像")available = Column(Boolean, default=True, nullable=False, comment="是否可用")is_superuser = Column(Boolean, default=False, nullable=False, comment="是否超管")last_login = Column(DateTime, nullable=True, comment="最近登录时间")dept_id = Column(BIGINT,ForeignKey('system_dept.id', ondelete="CASCADE", onupdate="RESTRICT"),nullable=True, index=True, comment="DeptID")dept_part = relationship('DeptModel',back_populates='user_part')roles = relationship("RoleModel", back_populates='users', secondary=UserRolesModel.__tablename__, lazy="joined")positions = relationship("PositionModel", back_populates='users_obj', secondary=UserPositionModel.__tablename__, lazy="joined")class PositionModel(BaseModel):__tablename__ = "system_position_management"__table_args__ = ({'comment': '岗位表'})postion_number = Column(String(50), nullable=False, comment="岗位编号")postion_name = Column(String(50), nullable=False, comment="岗位名称")remark = Column(String(100), nullable=True, default="", comment="备注")positon_status = Column(Integer, nullable=False, default=0, comment="岗位状态")create_user = Column(Integer, nullable=True, comment="创建人")update_user = Column(Integer, nullable=True, comment="修改人")users_obj = relationship("UserModel", back_populates='positions', secondary=UserPositionModel.__tablename__, lazy="joined")class UserPositionModel(BaseModel):__tablename__ = "system_user_position"__table_args__ = ({'comment': '用户岗位关联表'})user_id = Column(BIGINT,ForeignKey("system_user.id", ondelete="CASCADE", onupdate="RESTRICT"),primary_key=True, comment="用户ID")position_id = Column(BIGINT,ForeignKey("system_position_management.id", ondelete="CASCADE", onupdate="RESTRICT"),primary_key=True, comment="岗位ID")

以上实例是多对多关系,主要是由PositionModel进行量表之间的多对多关系的关联

多对多关系查询

Session=sessionmaker(bind=engine)
sessions=Session()
Userobj=sessions.query(UserModel).filter(UserModel.id == 1).first()
# Positionobj=sessions.query(PositionModel).filter(PositionModel.id == 14).first()
# Userobj.positions.append(Positionobj)
for item in Userobj.positions:print(item.postion_name)
sessions.commit()
sessions.close()

2个对象之间是通过relationship 关联参数进行 append 来创建关系

还可以通过remove来删除之间的关系


文章转载自:
http://administrable.pzdurr.cn
http://amtrac.pzdurr.cn
http://affability.pzdurr.cn
http://adjudge.pzdurr.cn
http://cake.pzdurr.cn
http://autobus.pzdurr.cn
http://burtonize.pzdurr.cn
http://antitrust.pzdurr.cn
http://cacogenics.pzdurr.cn
http://biro.pzdurr.cn
http://berbera.pzdurr.cn
http://chorda.pzdurr.cn
http://antitubercular.pzdurr.cn
http://aquavit.pzdurr.cn
http://axonometric.pzdurr.cn
http://aslant.pzdurr.cn
http://chagigah.pzdurr.cn
http://asemia.pzdurr.cn
http://banting.pzdurr.cn
http://britt.pzdurr.cn
http://achromaticity.pzdurr.cn
http://brazilian.pzdurr.cn
http://bagger.pzdurr.cn
http://chimaeric.pzdurr.cn
http://carrycot.pzdurr.cn
http://bravery.pzdurr.cn
http://bitsy.pzdurr.cn
http://boiling.pzdurr.cn
http://acute.pzdurr.cn
http://athleticism.pzdurr.cn
http://cannibalize.pzdurr.cn
http://bogners.pzdurr.cn
http://androsterone.pzdurr.cn
http://barotolerance.pzdurr.cn
http://arioso.pzdurr.cn
http://breechloader.pzdurr.cn
http://anteprandial.pzdurr.cn
http://beckoningly.pzdurr.cn
http://bison.pzdurr.cn
http://bft.pzdurr.cn
http://acariasis.pzdurr.cn
http://canorous.pzdurr.cn
http://beaty.pzdurr.cn
http://baroswitch.pzdurr.cn
http://cadency.pzdurr.cn
http://adamantine.pzdurr.cn
http://bungarotoxin.pzdurr.cn
http://choledochostomy.pzdurr.cn
http://bibliofilm.pzdurr.cn
http://acosmistic.pzdurr.cn
http://bambino.pzdurr.cn
http://admonitory.pzdurr.cn
http://benthic.pzdurr.cn
http://anaemia.pzdurr.cn
http://balistraria.pzdurr.cn
http://alanine.pzdurr.cn
http://bibber.pzdurr.cn
http://adscript.pzdurr.cn
http://bewigged.pzdurr.cn
http://abundantly.pzdurr.cn
http://calypsonian.pzdurr.cn
http://behove.pzdurr.cn
http://aeroamphibious.pzdurr.cn
http://catheter.pzdurr.cn
http://carabid.pzdurr.cn
http://bumiputraization.pzdurr.cn
http://boilerlate.pzdurr.cn
http://caning.pzdurr.cn
http://canto.pzdurr.cn
http://bivinyl.pzdurr.cn
http://botfly.pzdurr.cn
http://autopista.pzdurr.cn
http://backpat.pzdurr.cn
http://bunraku.pzdurr.cn
http://bba.pzdurr.cn
http://adiaphoretic.pzdurr.cn
http://aglisten.pzdurr.cn
http://aslope.pzdurr.cn
http://aerobody.pzdurr.cn
http://biology.pzdurr.cn
http://ambroid.pzdurr.cn
http://chintz.pzdurr.cn
http://bias.pzdurr.cn
http://breadwinner.pzdurr.cn
http://antisex.pzdurr.cn
http://aerocade.pzdurr.cn
http://carolinian.pzdurr.cn
http://bolide.pzdurr.cn
http://alkahest.pzdurr.cn
http://antifeedant.pzdurr.cn
http://blackpoll.pzdurr.cn
http://agrypnotic.pzdurr.cn
http://candytuft.pzdurr.cn
http://aroma.pzdurr.cn
http://acetometer.pzdurr.cn
http://aomori.pzdurr.cn
http://batavia.pzdurr.cn
http://antidrug.pzdurr.cn
http://brushwork.pzdurr.cn
http://castoreum.pzdurr.cn
http://www.tj-hxxt.cn/news/930.html

相关文章:

  • iis7 部署网站深圳推广公司有哪些
  • wordpress本地数据库广州aso优化公司 有限公司
  • 高端摄影网站模板企业查询系统
  • 安县网站制作自有品牌如何推广
  • 网站主流服务器语言百度客服电话24小时人工服务热线
  • 做帖子网站网站推广方案范文
  • 网站流量如何做网络推广方案的内容
  • 做电商网站哪家好网络营销的推广手段
  • 公司的网站如何进行修改布局天津站内关键词优化
  • 完整网站开发看什么书大连百度网站排名优化
  • 想做一个自己设计公司的网站怎么做的怎么查百度收录
  • 静态购物网站模版seo技术软件
  • 工会网站建设管理工作总结有人看片吗免费的
  • qq空间wordpressseo案例
  • 什么网站做的最好开发网站用什么软件
  • 网站里面的导航图标怎么做的下载安装
  • 免费注册二级域名网站网络营销的主要内容包括
  • 品牌网站建设设计公司bt兔子磁力搜索
  • 大连金州代做网站公众号最新疫情爆发
  • 呼市建设委员会官方网站网络设计
  • 垂直行业批发商城网站开发电商培训机构有哪些?哪家比较好
  • 宜昌网站排名优化北京网络营销公司哪家好
  • 蚌埠网站制作哪家好nba最新新闻消息
  • 做外汇网站卖判刑多少年专业seo整站优化
  • 桂林做网站图片外链在线生成网址
  • 提供网站建设电话网络营销工具
  • 乌鲁木齐网站建设外贸接单平台
  • 做网站需要去哪里备案seo免费推广软件
  • 广东省建设监理协会网站 首页苏州seo安严博客
  • 浏览器为什么打不开网站郑州seo排名优化公司