1

I am trying to build role based permission for my application. I am using flask security. I am stuck and bulding the data and relationship models for the application. Here is a snippet of the code:

roles_users= db.Table('roles_users',
    db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
    db.Column('role_id', db.Integer,db.ForeignKey('role.id')))
    
class role(db.Model,RoleMixin):
    __table_args__ = {"schema":"att"}
    __tablename__ = 'role'
    id= db.Column(db.Integer, primary_key=True) 
    name = db.Column(db.String(100))
    description= db.Column(db.String(255))   
    
    
class User(db.Model,UserMixin):
    __table_args__ = {"schema":"att"}
    id= db.Column(db.Integer, primary_key=True) 
    email = db.Column(db.String(100), unique=True)
    password= db.Column(db.String(255))
    rad = db.Column(db.String(10))
    active = db.Column(db.Boolean) 
    roles_users = db.relationship('role', secondary=roles_users,
    backref='user', lazy=True)

here is the error I am getting:


sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Triggering mapper: 'mapped class User->user'. Original exception was: Foreign key associated with column 'roles_users.role_id' could not find table 'role' with which to generate a foreign key to target column 'id'


bsam
  • 53
  • 1
  • 4
  • Does this answer your question? [SQLalchemy not find table for creating foreign key](https://stackoverflow.com/questions/28047027/sqlalchemy-not-find-table-for-creating-foreign-key) – Nick K9 Feb 22 '21 at 19:30

0 Answers0