role字段加入信息出错
来源:3-8 .管理员-登录日志-操作日志数据模型设计
伟大的五年
2018-01-09
# from app import app 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:mysql@172.16.23.148:3306/flask_home' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True db = SQLAlchemy(app) class BaseModel(object): addtime = db.Column(db.DateTime, index=True, default=datetime.now) updatetime = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now) # 前台数据模型 class User(BaseModel, db.Model): """ 用户模型 """ __table_name__ = "user" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(20), nullable=False, unique=True) phone = db.Column(db.String(11)) pwd = db.Column(db.String(100), nullable=False) emial = db.Column(db.String(100), unique=True) info = db.Column(db.Text) face = db.Column(db.String(100)) # 用户的头像 uuid = db.Column(db.String(255)) userlogin = db.relationship("UserLog", backref="user") comment = db.relationship("Comment", backref="user") moviecol = db.relationship("Moivecol", backref="user") def __repr__(self): return "<User %r>" % self.name class UserLog(BaseModel, db.Model): """ 用户的登录日志 """ __tablename__ = "userlog" id = db.Column(db.Integer, primary_key=True) ip = db.Column(db.String(100)) user_id = db.Column(db.Integer, db.ForeignKey("user.id")) def __repr__(self): return "<UserLog %r>" % self.id class Tag(BaseModel, db.Model): """ 标签 """ __tablename__ = "tag" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), unique=True) movie = db.relationship("Moive", backref="tag") def __repr__(self): return "<Tag %r>" % self.name class Moive(BaseModel, db.Model): """ 电影信息 """ __tablename__ = "movie" id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(255), unique=True) info = db.Column(db.Text) url = db.Column(db.String(255), unique=True) logo = db.Column(db.String(255), unique=True) star = db.Column(db.SMALLINT) playnum = db.Column(db.BIGINT) commentnum = db.Column(db.BIGINT) relase_time = db.Column(db.Date) # 上映时间 area = db.Column(db.String(255)) # 上映地区 length = db.Column(db.String(100)) # 电影时长 tag_id = db.Column(db.Integer, db.ForeignKey("tag.id")) moviecols = db.relationship("Moivecol", backref="movie") comment = db.relationship("Comment", backref="movie") def __repr__(self): return "<Movie %r>" % self.id class Preview(BaseModel, db.Model): """ 电影预告 """ __tablename__ = "preview" id = db.Column(db.Integer, primary_key=True) logo = db.Column(db.String(255), unique=True) title = db.Column(db.String(255), unique=True) def __repr__(self): return "<Preview %r>" % self.title class Moivecol(BaseModel, db.Model): """ 电影收藏 """ __tablename__ = "moviecol" id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey("user.id")) movie = db.Column(db.Integer, db.ForeignKey("movie.id")) def __repr__(self): return "<Moivecol %r>" % self.id class Comment(BaseModel, db.Model): """ 电影评论 """ __tablename__ = "comment" id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey("user.id")) movie = db.Column(db.Integer, db.ForeignKey("movie.id")) content = db.Column(db.Text) def __repr__(self): return "<Comment %r>" % self.id # 后台站点模型对象 class Auth(BaseModel, 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) def __repr__(self): return "<Auth %r>" % self.name class Role(BaseModel, 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)) admin = db.relationship("Admin", backref="role") def __repr__(self): return "<Auth %r>" % self.name class Admin(BaseModel, db.Model): """ 管理员 """ __tablename__ = "admin" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100)) pwd = db.Column(db.String(100)) is_super = db.Column(db.SmallInteger) # 0表示是超级管理员 role_id = db.Column(db.Integer, db.ForeignKey("role.id")) adminlog = db.relationship("AdminLog", backref="admin") oplog = db.relationship("opLog", backref="admin") def __repr__(self): return "<Auth %r>" % self.name class AdminLog(BaseModel, 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)) def __repr__(self): return "<AdminLog %r>" % self.id class opLog(BaseModel, 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)) reason = db.Column(db.String(600)) def __repr__(self): return "<opLog %r>" % self.id if __name__ == '__main__': # db.drop_all() # db.create_all() role = Role(name="超级管理员", auths="") db.session.add(role) db.session.commit()
报错信息:
sqlalchemy.exc.ArgumentError: Error creating backref 'movie' on relationship 'Moive.moviecols': property of that name exists on mapper 'Mapper|Moivecol|moviecol'
写回答
1回答
-
慕沐9123820
2018-01-13
我也是这步出错,你解决了吗?
00
相似问题