Files
order/建表
2023-10-23 00:13:06 +08:00

34 lines
1.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
1.linux数据库操作
mysql -uroot -p
数据库密码123456
创建数据表
数据库名food_db
CREATE DATABASE `food_db` DEFAULT CHARACTER SET = `utf8mb4`;
查看表
show databases;
进入数据表
use food_db;
接着在粘贴建表语句,如下:
create TABLE `user` (
`uid` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '用户uid',
`nickname` varchar(100) NOT NULL DEFAULT '' COMMENT '用户名',
`mobile` varchar(20) NOT NULL DEFAULT '' COMMENT '手机号码',
`email` varchar(100) NOT NULL DEFAULT '' COMMENT '邮箱地址',
`sex` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1男 2女 0没填写',
`avatar` varchar(64) NOT NULL DEFAULT '' COMMENT '头像',
`login_name` varchar(20) NOT NULL DEFAULT '' COMMENT '登录用户名',
`login_pwd` varchar(32) NOT NULL DEFAULT '' COMMENT '登录密码',
`login_salt` varchar(32) NOT NULL DEFAULT '' COMMENT '登录密码的随机加密秘钥',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '1有效 0无效',
`updated_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次更新时间',
`created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '插入时间',
PRIMARY KEY (`uid`),
UNIQUE KEY `login_name` (`login_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表(管理员)';
2.使用flask-sqlacodegen扩展快速生成ORM model
在orderr目录下输入
flask-sqlacodegen " mysql://root:~renjianbo0118mysql*&;@127.0.0.1/food_db" --tables deviceinfo --outfile "common/models/member/DeviceInfo.py" --flask
3.修改自动生成的model中的db变量 (很重要)
from application import db