from flask import Flask from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' db = SQLAlchemy(app) class Book(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(80), nullable=False) author_id = db.Column(db.Integer, db.ForeignKey('author.id'), nullable=False) author = db.relationship('Author', backref=db.backref('books', lazy=True)) class Author(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80), nullable=False)In this example, we have two tables: `Book` and `Author`. The `Book` table has a foreign key column called `author_id` that references the primary key of the `Author` table. We use the `db.ForeignKey()` function to specify the relationship between the two tables. The `db.relationship()` function is used to create a relationship between the `Book` and `Author` classes. This function takes two arguments: the name of the related class (in this case, `Author`), and the `backref` argument, which specifies the name of the attribute that will be added to the related class that allows us to reference back to the `Book` instance. In conclusion, Flask-SQLAlchemy is a package library that provides a set of tools for working with databases using SQLAlchemy. The ForeignKey constraint is a key feature of SQLAlchemy that allows developers to establish relationships between tables in a database.