Forum >> Programmazione Python >> Web e Reti >> aiuto con flask-sqlalchemy

Pagina: 1

ciao a tutti, sto provando a creare un blog in flask seguendo una guida.
mi sono imbattuto in un errore che non so come risolvere
Traceback (most recent call last):
File "manage.py", line 5, in <module>
app = create_app()
File "C:\Users\preside\Desktop\flask\project\blog\__init__.py", line 16, in cr
eate_app
from .models import User, Role
File "C:\Users\preside\Desktop\flask\project\blog\models.py", line 25, in <mod
ule>
class User(db.Model, UserMixin):
File "C:\Users\preside\Desktop\flask\project\blog\models.py", line 28, in User

email = db.Column(db.String(255), unique=True, required=True)
File "C:\Users\preside\Desktop\flask\venv\lib\site-packages\sqlalchemy\sql\sch
ema.py", line 1257, in __init__
"Unknown arguments passed to Column: " + repr(list(kwargs)))
sqlalchemy.exc.ArgumentError: Unknown arguments passed to Column: ['required']

mentre il file in cui riporta l'errore è questo
from . import db
from flask_security import UserMixin, RoleMixin
from datetime import datetime

roles_users = db.Table('roles_users',
db.Column('user_id', db.Integer(), db.ForeignKey('users.id')),
db.Column('role_id', db.Integer(), db.ForeignKey('roles.id')))

class Role(db.Model, RoleMixin):
__tablename__ = 'roles'
id = db.Column(db.Integer(), primary_key=True)
name = db.Column(db.String(80), unique=True)
description = db.Column(db.String(255))

def __repr__(self):
return "<Role %r>"%self.name
@staticmethod
def insert_roles():
for role_name in "admin publisher user".split():
if Role.query.filter_by(name=role_name).first() is None:
role = Role(name = role_name)
db.session.add(role)
db.session.commit()

class User(db.Model, UserMixin):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(255), unique=True, required=True)
password = db.Column(db.String(255))
active = db.Column(db.Boolean())
confirmed_at = db.Column(db.DateTime())
username = db.Column(db.String(255))
about = db.Column(db.Text())
roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic'))

def __repr__(self):
return "<User %r>"%self.email
@staticmethod
def insert_admin():
from flask import current_app
if User.query.filter_by(email=current_app.config['BLOG_ADMIN_MAIL']).first() is None:
user = User(
email=current_app.config['BLOG_ADMIN_MAIL'],
password=current_app.config['BLOG_ADMIN_PASSWORD'],
active=True)
user.roles.append(Role.query.filter_by(name='admin').first())
db.session.add(user)
db.session.commit()

come posso fare?
grazie in anticipo


Pagina: 1



Esegui il login per scrivere una risposta.