Flask アプリに登録しようとしています。私はすでに 2 つの役割 (「管理者」と「ユーザー」) と 1 つの管理者 (私) を問題なく作成しています。ただし、登録ページから新しいユーザーを登録しようとすると、次のエラーが発生します。
user.role_id may not be NULL
モデル (標準クイックスタート): クラス Role(db.Model, RoleMixin): name = CharField(unique=True) description = TextField(null=True)
class User(db.Model, UserMixin):
email = TextField()
password = TextField()
active = BooleanField(default=True)
confirmed_at = DateTimeField(null=True)
class UserRoles(db.Model):
# Because peewee does not come with built-in many-to-many
# relationships, we need this intermediary class to link
# user to roles.
user = ForeignKeyField(User, related_name='roles')
role = ForeignKeyField(Role, related_name='users')
name = property(lambda self: self.role.name)
description = property(lambda self: self.role.description)
これがどこから来ているのか本当にわかりません。まず、新しいユーザーにロールを割り当てる必要はありません。次に、「ロール」は外部キーであるため、ユーザーのロール ID を取得する正しい方法user.role.id
はuser.role_id
.