0

I am facing an Argument error while trying to run migrations, but I have failed to figure out where the problem is, What am trying to implement is a relationship between two models. Below is my model class :

class TourPackages(db.Model):
    __tablename__ = 'tour_package'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))
    description = db.Column(db.TEXT)
    price = db.Column(db.Float)
    destination = db.relationship('Destinations', backref='tourpackages', lazy=True)
    capacity = db.Column(db.Integer)

    @property
    def serialize(self):
        return {
            'name': self.name,
            'description': self.destination,
            'price': self.price,
            'destination': self.destination,
            'capacity': self.capacity
        }


class Destinations(db.Model):
    __tablename__ = 'destination'

    id = db.Column(db.Integer)
    location = db.Column(db.String(50))
    danger_type = db.Column(db.String(50))

When I run migrations with the command below:

flask db migrate -m "Initial migration."

I get this error :

sqlalchemy.exc.ArgumentError: Mapper mapped class Destinations->destination could not assemble any primary key columns for mapped table 'destination'

What am I doing wrong here

1 Answer 1

1

In your Destinations model, you need to change the id column to be a primary key

id = db.Column(db.Integer, primary_key=True)

and add a foreign key column for the relationship, again in Destinations:

tourpackages_id = db.Column(db.Integer, db.ForeignKey('tour_package.id'))

See the documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.