我一直收到此错误sqlalchemy.exc。操作错误:(sqlite3.OperationalError)没有这样的表:user但我不知道为什么,因为我使用命令sqlite3 database.db和.tables在good目录下创建了我的数据库。我尝试了db.create_all(),但如果它在db声明之前,它当然不起作用,但如果我将它放在它之后,它不会更改任何内容
我还有另一个问题,那就是数据库。"”总是被标记为错误。我试着安装pylint-flask并将其加载到设置中。它工作了大约5分钟,然后错误再次出现('SQLAlchemy'的示例没有'Column' memberpylint(no-member))
from flask import Flask, render_template, redirect, url_for
from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField
from wtforms.validators import InputRequired, Email, Length
from flask_sqlalchemy import SQLAlchemy
from werkzeug.security import generate_password_hash, check_password_hash
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user
app = Flask(__name__)
app.config['SECRET_KEY'] = 'Thisissupposedtobesecret!'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///sqlite-tools-win32-x86-3290000/database.db'
bootstrap = Bootstrap(app)
db = SQLAlchemy(app)
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'
class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(15), unique=True)
email = db.Column(db.String(50), unique=True)
password = db.Column(db.String(80))
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
class LoginForm(FlaskForm):
username = StringField('username', validators=[InputRequired(), Length(min=4, max=15)])
password = PasswordField('password', validators=[InputRequired(), Length(min=8, max=80)])
remember = BooleanField('remember me')
class RegisterForm(FlaskForm):
email = StringField('email', validators=[InputRequired(), Email(message='Invalid email'), Length(max=50)])
username = StringField('username', validators=[InputRequired(), Length(min=4, max=15)])
password = PasswordField('password', validators=[InputRequired(), Length(min=8, max=80)])
1条答案
按热度按时间cngwdvgl1#
在定义了Model之后,您需要调用
create_all()
来更新对数据库的更改。例如..