运行models.py 有问题
来源:3-8 .管理员-登录日志-操作日志数据模型设计
Yp_Australia
2017-12-07
错误信息
C:\Users\xiong\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pymysql\cursors.py:166: Warning: (1366, "Incorrect string value: '\\xB0\\xC4\\xB4\\xF3\\xC0\\xFB...' for column 'VARIABLE_VALUE' at row 480")
result = self._query(query)
# coding:utf8 from flask import Flask from flask_sqlalchemy import SQLAlchemy from datetime import datetime import pymysql app = Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"] = 'mysql+pymysql://root:xiong1pin@localhost/movie' app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True; db = SQLAlchemy(app) # our User class User(db.Model): __tablename__ = "user" id = db.Column(db.Integer, primary_key=True) # 编号 name = db.Column(db.String(100), unique=True) pwd = db.Column(db.String(100)) email = db.Column(db.String(100), unique=True) phone = db.Column(db.String(11), unique=True) info = db.Column(db.Text) face = db.Column(db.String(255), unique=True) # profile addtime = db.Column(db.DateTime, index=True, default=datetime.now) # register time uuid = db.Column(db.String(255), unique=True) # 唯一标识符 userlogs = db.relationship('Userlog', backref='user') # if you need to add a foreignKey, comments = db.relationship('Comments', backref='user') moviecols = db.relationship('Moviecol', backref='user') def __repr__(self): return "<User %r>" % self.name # 会员登录日志 class Userlog(db.Model): __tablename__ = "userlog" id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) ip = db.Column(db.String(100)) # login_IP_Address addtime = db.Column(db.DateTime, index=True, default=datetime.now) def __repr__(self): return '<Userlog %r>' % self.id # 电影标签 class Tag(db.Model): __tablename__ = 'tag' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), unique=True) addtime = db.Column(db.DateTime, index=True, default=datetime.now) movies = db.relationship('Moive', backref='tag') def __repr__(self): return '<Tag %r>' % self.name # movie class Movie(db.Model): __tablename__ = 'movie' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(255), unique=True) url = db.Column(db.String(255), unique=True) info = db.Column(db.Text) logo = db.Column(db.String(255), unique=True) star = db.Column(db.SmallInteger) playnum = db.Column(db.BigInteger) commentnum = db.Column(db.BigInteger) tag_id = db.Column(db.Integer, db.ForeignKey('tag.id')) area = db.Column(db.String(255)) release_time = db.Column(db.Date) length = db.Column(db.String(100)) # 播放时间 addtime = db.Column(db.DateTime, index=True, default=datetime.now) comments = db.relationship('Comment', backref='movie') moviecols = db.relationship('Moviecol', backref='movie') def __repr__(self): return '<Movie %r>' % self.title class Preview(db.Model): __tablename__ = 'priview' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(255), unique=True) logo = db.Column(db.String(255), unique=True) addtime = db.Column(db.DateTime, index=True, default=datetime.now) def __repr__(self): return '<Preview %r>' % self.title class Comment(db.Model): __tablename__ = 'comment' id = db.Column(db.Integer, primary_key=True) content = db.Column(db.Text) movie_id = db.Column(db.Integer, db.ForeignKey('movie.id')) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) addtime = db.Column(db.DateTime, index=True, default=datetime.now) def __repr__(self): return '<Comment %r>' % self.id class Moviecol(db.Model): __tablename__ = 'moviecol' id = db.Column(db.Integer, primary_key=True) movie_id = db.Column(db.Integer, db.ForeignKey('movie.id')) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) addtime = db.Column(db.DateTime, index=True, default=datetime.now) def __repr__(self): return '<Moviecol %r>' % self.id # if the route matches the route in this class, we can say this person has the right, vice versa. class Auth(db.Model): __tablename__ = 'auth' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), unique=True) url = db.Column(db.String(255), unique=True) addtime = db.Column(db.DateTime, index=True, default=datetime.now) def __repr__(self): return '<Auth %r>' % self.name # 角色 class Role(db.Model): __tablename__ = 'role' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), unique=True) auths = db.Column(db.String(600)) addtime = db.Column(db.DateTime, index=True, default=datetime.now) def __repr__(self): return '<Role %r>' % self.name class Admin(db.Model): __tablename__ = "admin" id = db.Column(db.Integer, primary_key=True) # 编号 name = db.Column(db.String(100), unique=True) pwd = db.Column(db.String(100)) is_super = db.Column(db.SmallInteger) # whether he/she is a superAdmin, 0 stands for 'Yes' role_id = db.Column(db.Integer, db.ForeignKey('role.id')) # 所属角色 addtime = db.Column(db.DateTime, index=True, default=datetime.now) adminlogs = db.relationship('Adminlog', backref='admin') oplogs = db.relationship('Oplog', backref='admin') def __repr__(self): return '<Admin %r>' % self.name # 管理员登陆日志 class Adminlog(db.Model): __tablename__ = "adminlog" id = db.Column(db.Integer, primary_key=True) admin_id = db.Column(db.Integer, db.ForeignKey('admin.id')) ip = db.Column(db.String(100)) # login_IP_Address addtime = db.Column(db.DateTime, index=True, default=datetime.now) def __repr__(self): return '<Adminlog %r>' % self.id # 修改日志 class Oplog(db.Model): __tablename__ = "oplog" id = db.Column(db.Integer, primary_key=True) admin_id = db.Column(db.Integer, db.ForeignKey('admin.id')) ip = db.Column(db.String(100)) # login_IP_Address reason = db.Column(db.String(600)) # the reason for rectification addtime = db.Column(db.DateTime, index=True, default=datetime.now) def __repr__(self): return '<Oplog %r>' % self.id if __name__ == '__main__': db.create_all()
2回答
-
需要设置MySQL数据库字符集全部为utf8
Windows下MySQL的修改字符集编码为UTF8(解决中文乱码问题)
MySQL配置文件中复制文件my-default.ini(是复制不是直接修改文件名),复制之后重命名为my.ini
修改mysql的my.ini文件中的字符集键值(注意配置的字段细节):
1、在[client]字段里加入default-character-set=utf8,如下:
[client]
default-character-set=utf8
2、在[mysqld]字段里加入character-set-server=utf8,如下:
[mysqld]
character-set-server=utf8
3、在[mysql]字段里加入default-character-set=utf8,如下:
[mysql]
default-character-set=utf8
修改完成后,重启MySQL
012017-12-13 -
Yp_Australia
提问者
2017-12-07
我已经在cmd中用了:
mysql>alter database movie character set utf8;
00
相似问题