Flask_SQLAlchemy doesn't install properly | Python | Linux server | Rpi5

March 10, 2024, 13:13

tarkaguy

Hello, I'm trying Rest API and I want to make a database using Flask_SQLAlchemy but for some unknown reason when I install it, it doesn't let me fully use the library. Such as functions like Column. When I try running main.py:
sqlalchemy.exc.ArgumentError: Mapper Mapper[VideoModel(video_model)] could not assemble any primary key columns for mapped table 'video_model'
I tried installing using:
pip install Flask-SQLAlchemy
sudo apt-get install python3-flask-sqlalchemy 
Both worked and output that it's already installed.

tarkaguy

Part of main.py script where I use Flask_SQLAlchemy:
python
from flask import Flask
from flaskrestful import Api, Resource, reqparse, abort
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name)
api = Api(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
db = SQLAlchemy(app)


class VideoModel(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.string(100), nullable=False)
    views = db.Column(db.integer, nullable=False)
    likes = db.Column(db.integer, nullable=False)

    def repr(self):
        return f"Video(name={name}, views={views}, likes={likes})"

db.create_all()