R
R
Ricknom2018-08-13 14:51:42
Flask
Ricknom, 2018-08-13 14:51:42

Relationship between models in different blueprints?

I need to link two models that are in different blueprints.
I tried to do it like this:

from app import db
from datetime import datetime
from app.user.models import User

class Chapter(db.Model):
  id = db.Column(db.Integer(), primary_key=True)
  add_date = db.Column(db.DateTime(), default=datetime.utcnow)
  name = db.Column(db.String())
  img = db.Column(db.String())
  uploader_id = db.Column(db.Integer,db.ForeignKey('uploader.id'))
  uploader = db.relationship('User', 
      backref=db.backref('uploaded_chapters', lazy=True))

but when I try to run the application, it gives the error
"sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column 'chapter.uploader_id' could not find table 'uploader' with which to generate a foreign key to target column 'id'"
What am I doing wrong ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2018-08-18
@skipirich

Is the uploader also in another file? Maybe try importing it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question