老师,还是不行
来源:7-1 .管理员登录
3Words
2017-08-09
5回答
-
3Words
提问者
2017-08-09
老师,这次应该都改对了吧,可还是不行, 崩溃了。。00 -
3Words
提问者
2017-08-09
老师这是数据库编码。数据表的的编码我也都改成UTF8了。 还不行
00 -
3Words
提问者
2017-08-09
报错信息:
/home/lining/movie/bin/python /home/lining/PycharmProjects/movie_app/app/models.py
Traceback (most recent call last):
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1182, in _execute_context
context)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/engine/default.py", line 470, in do_execute
cursor.execute(statement, parameters)
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
result = self._query(query)
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
conn.query(q)
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/connections.py", line 856, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/connections.py", line 1057, in _read_query_result
result.read()
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/connections.py", line 1340, in read
first_packet = self.connection._read_packet()
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/connections.py", line 1014, in _read_packet
packet.check_error()
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/connections.py", line 393, in check_error
err.raise_mysql_exception(self._data)
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.InternalError: (1366, "Incorrect string value: '\\xE8\\xB6\\x85\\xE7\\xBA\\xA7...' for column 'name' at row 1")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/lining/PycharmProjects/movie_app/app/models.py", line 213, in <module>
db.session.commit()
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/scoping.py", line 157, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 906, in commit
self.transaction.commit()
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 461, in commit
self._prepare_impl()
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 441, in _prepare_impl
self.session.flush()
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 2171, in flush
self._flush(objects)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 2291, in _flush
transaction.rollback(_capture_exception=True)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 187, in reraise
raise value
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 2255, in _flush
flush_context.execute()
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/unitofwork.py", line 389, in execute
rec.execute(self)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/unitofwork.py", line 548, in execute
uow
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/persistence.py", line 181, in save_obj
mapper, table, insert)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/persistence.py", line 835, in _emit_insert_statements
execute(statement, params)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 945, in execute
return meth(self, multiparams, params)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/sql/elements.py", line 263, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1053, in _execute_clauseelement
compiled_sql, distilled_params
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1189, in _execute_context
context)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1402, in _handle_dbapi_exception
exc_info
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 186, in reraise
raise value.with_traceback(tb)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1182, in _execute_context
context)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/engine/default.py", line 470, in do_execute
cursor.execute(statement, parameters)
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
result = self._query(query)
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
conn.query(q)
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/connections.py", line 856, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/connections.py", line 1057, in _read_query_result
result.read()
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/connections.py", line 1340, in read
first_packet = self.connection._read_packet()
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/connections.py", line 1014, in _read_packet
packet.check_error()
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/connections.py", line 393, in check_error
err.raise_mysql_exception(self._data)
File "/home/lining/movie/lib/python3.5/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1366, "Incorrect string value: '\\xE8\\xB6\\x85\\xE7\\xBA\\xA7...' for column 'name' at row 1") [SQL: 'INSERT INTO `role` (name, auths, addtime) VALUES (%(name)s, %(auths)s, %(addtime)s)'] [parameters: {'auths': '', 'addtime': datetime.datetime(2017, 8, 9, 3, 20, 11, 979236), 'name': '超级管理员'}]
Process finished with exit code 100 -
3Words
提问者
2017-08-09
这里是我的modei.py 和 __init__.py的代码
# coding:utf8
from datetime import datetime
from app import db
# 会员
class User(db.Model):
__tablename__ = "user"
__table_args__ = {"useexisting":True}
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) # 头像
addtime = db.Column(db.DateTime, index=True, default=datetime.utcnow) # 登录时间
uuid = db.Column(db.String(255), unique=True) # 唯一标识符
userlogs = db.relationship('Userlog', backref='user') # 会员日志外键关系关联
comments = db.relationship('Comment', backref='user') # 评论外键关联
moviecols = db.relationship('Moviecol', backref='user') # 收藏外键关联
def __repr__(self):
return "User %r" % self.name
# 会员登录日志
class Userlog(db.Model):
__tablename__ = "userlog"
__table_args__ = {"useexisting": True}
id = db.Column(db.Integer, primary_key=True) # 编号
user_id = db.Column(db.Integer, db.ForeignKey('user.id')) # 所属会员
ip = db.Column(db.String(100)) # 登录IP
addtime = db.Column(db.DateTime, index=True, default=datetime.utcnow) # 登录时间
def __repr__(self):
return "<Userlog %r>" % self.id
# 标签
class Tag(db.Model):
__tablename__ = "tag"
__table_args__ = {"useexisting": True}
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.utcnow) # 添加时间
movies = db.relationship("Movie", backref='tag') # 电影外键关联
def __repr__(self):
return "<tag %r>" % self.name
# 电影
class Movie(db.Model):
__tablename__ = "movie"
__table_args__ = {"useexisting": True}
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.utcnow) # 添加时间
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__ = "preview"
__table_args__ = {"useexisting": True}
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.utcnow) # 添加时间
def __repr__(self):
return "<Preview %r>" % self.title
# 评论
class Comment(db.Model):
__tablename__ = "comment"
__table_args__ = {"useexisting": True}
id = db.Column(db.Integer, primary_key=True) # 编号
comment = 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.utcnow) # 添加时间
def __repr__(self):
return "<Comment %r>" % self.id
# 电影收藏
class Moviecol(db.Model):
__tablename__ = "moviecol"
__table_args__ = {"useexisting": True}
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.utcnow) # 添加时间
def __repr__(self):
return "<Moviecol> %r" % self.id
# 权限
class Auth(db.Model):
__tablename__ = "auth"
__table_args__ = {"useexisting": True}
id = db.Column(db.Integer, primary_key=True) # 编号
name = db.Column(db.String(255), unique=True) # 名称
url = db.Column(db.String(255), unique=True) # 地址
addtime = db.Column(db.DateTime, index=True, default=datetime.utcnow) # 添加时间
def __repr__(self):
return "<Auth %r>" % self.name
# 角色
class Role(db.Model):
__tablename__ = "role"
__table_args__ = {"useexisting": True}
id = db.Column(db.Integer, primary_key=True) # 编号
name = db.Column(db.String(255), unique=True) # 名称
auths = db.Column(db.String(600)) # 权限
addtime = db.Column(db.DateTime, index=True, default=datetime.utcnow) # 添加时间
admins = db.relationship('Admin', backref='role') # 管理员外键关联
def __repr__(self):
return "<Role %r>" % self.name
# 管理员
class Admin(db.Model):
__tablename__ = "admin"
__table_args__ = {"useexisting": True}
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) # 是否为管理员
role_id = db.Column(db.Integer, db.ForeignKey('role.id'))
addtime = db.Column(db.DateTime, index=True, default=datetime.utcnow) # 添加时间
adminlogs = db.relationship('Adminlog', backref='admin') # 外键
oplogs = db.relationship('Oplog', backref='admin')
def __repr__(self):
return "<Admin %r>" % self.name
def check_pwd(self, pwd):
from werkzeug.security import check_password_hash
return check_password_hash(self.pwd, pwd)
# 管理员登录日志
class Adminlog(db.Model):
__tablename__ = "adminlog"
__table_args__ = {"useexisting": True}
id = db.Column(db.Integer, primary_key=True) # 编号
admin_id = db.Column(db.Integer, db.ForeignKey('admin.id')) # 所属会员
ip = db.Column(db.String(100)) # 登录IP
addtime = db.Column(db.DateTime, index=True, default=datetime.utcnow) # 登录时间
def __repr__(self):
return "<Admin log %r>" % self.id
# 操作日志
class Oplog(db.Model):
__tablename__ = "oplog"
__table_args__ = {"useexisting": True}
id = db.Column(db.Integer, primary_key=True) # 编号
admin_id = db.Column(db.Integer, db.ForeignKey('admin.id')) # 所属会员
ip = db.Column(db.String(100)) # 登录IP
addtime = db.Column(db.DateTime, index=True, default=datetime.utcnow) # 登录时间
reason = db.Column(db.String(600)) # 原因
def __repr__(self):
return "<Oplog %r>" % self.id
if __name__ == "__main__":
db.create_all()
role = Role(
name="超级管理员",
auths=""
)
db.session.add(role)
db.session.commit()
from werkzeug.security import generate_password_hash
admin = Admin(
name="lining",
pwd=generate_password_hash("liningoi"),
is_super=0,
role_id=1
)
db.session.add(admin)
db.session.commit()__init.py
# coding: utf8
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
import pymysql
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "mysql+pymysql://root:liningoi@127.0.0.1:3306/movie"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
app.config["SECRET_KEY"] = '9dbf7f11ae464a3cbc3ca9154431ed6b'
app.debug = True
db = SQLAlchemy(app)
from app.home import home as home_blueprint
from app.admin import admin as admin_blueprint
app.register_blueprint(home_blueprint)
app.register_blueprint(admin_blueprint, url_prefix="/admin")
@app.errorhandler(404)
def page_not_found(error):
return render_template("home/404.html"), 404012017-08-17 -
3Words
提问者
2017-08-09
/home/lining/movie/bin/python /home/lining/PycharmProjects/movie_app/app/models.py
Traceback (most recent call last):
File "/home/lining/PycharmProjects/movie_app/app/models.py", line 212, in <module>
auths=""
File "<string>", line 2, in __init__
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/instrumentation.py", line 347, in _new_state_if_none
state = self._state_constructor(instance, self)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/util/langhelpers.py", line 764, in __get__
obj.__dict__[self.__name__] = result = self.fget(obj)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/instrumentation.py", line 177, in _state_constructor
self.dispatch.first_init(self, self.class_)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/event/attr.py", line 256, in __call__
fn(*args, **kw)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/mapper.py", line 2976, in _event_on_first_init
configure_mappers()
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/mapper.py", line 2872, in configure_mappers
mapper._post_configure_properties()
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/mapper.py", line 1765, in _post_configure_properties
prop.init()
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/interfaces.py", line 184, in init
self.do_init()
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/relationships.py", line 1653, in do_init
self._process_dependent_arguments()
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/relationships.py", line 1710, in _process_dependent_arguments
self.target = self.mapper.mapped_table
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/util/langhelpers.py", line 764, in __get__
obj.__dict__[self.__name__] = result = self.fget(obj)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/orm/relationships.py", line 1626, in mapper
argument = self.argument()
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/ext/declarative/clsregistry.py", line 281, in __call__
x = eval(self.arg, globals(), self._dict)
File "<string>", line 1, in <module>
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/util/_collections.py", line 729, in __missing__
self[key] = val = self.creator(key)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/ext/declarative/clsregistry.py", line 262, in _access_cls
return _determine_container(key, cls._decl_class_registry[key])
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/ext/declarative/clsregistry.py", line 246, in _determine_container
value = value.attempt_get([], key)
File "/home/lining/movie/lib/python3.5/site-packages/sqlalchemy/ext/declarative/clsregistry.py", line 91, in attempt_get
(".".join(path + [key]))
sqlalchemy.exc.InvalidRequestError: Multiple classes found for path "Adminlog" in the registry of this declarative base. Please use a fully module-qualified path.
Process finished with exit code 10212017-08-09
相似问题