I am trying to make registration in my Flask app work. I have already created two roles ("admin" and "user") and one admin (me) without any problems. However, when I try to register a new user through the registration page, I get the following error:
user.role_id may not be NULL
Models (standard quickstart): class 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)
I really don't get where this is coming from. Firstly, you don't need to assign a role to a new user, and secondly, since 'role' is a foreign key, the correct way to get the users' role id would be user.role.id
instead of user.role_id
.