码迷,mamicode.com
首页 > 数据库 > 详细

sqlchemy self made

时间:2018-10-27 11:54:16      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:import   maker   create   vol   incr   sel   second   creat   step   

# -*- coding: utf-8 -*-
from sqlalchemy import create_engine, Column, String, Integer, ForeignKey, Table,Text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relationship

DB_URI = "mysql+pymysql://root:root@127.0.0.1:3306/xiachufang2"
engine = create_engine(DB_URI)
Base = declarative_base(engine)
session = sessionmaker(engine)()

class Recipe_Mat(Base):
    __tablename__ = ‘recipe_mat‘
    material_id = Column(Integer, ForeignKey(‘material.id‘),primary_key=True)
    food_id = Column(Integer, ForeignKey(‘food.id‘),primary_key=True)

class Recipe(Base):
    __tablename__=‘food‘
    id=Column(Integer,autoincrement=True,primary_key=True)
    food=Column(String(128),nullable=False)
    step=Column(Text)
    tip=Column(Text)
    description=Column(Text)
    materials=relationship(‘Material‘,secondary=‘recipe_mat‘)


class Material(Base):
    __tablename__ = ‘material‘
    id = Column(Integer, autoincrement=True, primary_key=True)
    material = Column(String(128), nullable=False)
    volume=Column(String(128))
    foods = relationship(‘Recipe‘, secondary=‘recipe_mat‘)

  

sqlchemy self made

标签:import   maker   create   vol   incr   sel   second   creat   step   

原文地址:https://www.cnblogs.com/pythonClub/p/9860449.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!