day12_03 orm创建mysql表结构

Posted flytoyou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了day12_03 orm创建mysql表结构相关的知识,希望对你有一定的参考价值。

# Author:Adminone

from sqlalchemy import Table, MetaData, Column, Integer, String, ForeignKey
from sqlalchemy.orm import mapper

metadata = MetaData()

user = Table(\'user\', metadata,
             Column(\'id\', Integer, primary_key=True),
             Column(\'name\', String(50)),
             Column(\'fullname\', String(50)),
             Column(\'password\', String(12))
             )


class User(object):
    def __init__(self, name, fullname, password):
        self.name = name
        self.fullname = fullname
        self.password = password


mapper(User,user)  # the table metadata is created separately with the Table construct, then associated with the User class via the mapper() function

以上是关于day12_03 orm创建mysql表结构的主要内容,如果未能解决你的问题,请参考以下文章

MYSQL03_SQL的概述规则和规范基本的SELECT语句显示表结构

Django day005

Django orm的使用

mysql-day03笔记

python—day60 Object Relational Mapping(ORM) ORM连表查询 ORM进阶

如何创建临时表而不丢失 django 中的 ORM?