Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Flask-Migration with one-to-many relationship

guarillamail:

I have a working blog system. I want to add it to comment system. I completed migrations with post model with id, title and body.

Now I add comments and create new model named Comment. When I run migrations:

INFO [alembic.runtime.migration] Context impl MySQLImpl.

INFO [alembic.runtime.migration] Will assume non-transactional DDL.

INFO [alembic.env] No changes in schema detected.


from run import db

class Post(db.Model):
__tablename__ = 'blog.post'
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String, nullable=False)
body = db.Column(db.Text, nullable=False)

comments = db.relationship('Comment', backref='blog.post')


from run import db


class Comment(db.Model):
__tablename__ = 'blog.comment'
id = db.Column(db.Integer, primary_key=True)
body = db.Column(db.Text, nullable=False)

post_id = db.Column(db.Integer, db.ForeignKey('blog.post.id'), nullable=False)

I dont know what is wrong with my code. I get relationship from documentation and edit it. There aren't any comment table in db before.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Flask-Migration with one-to-many relationship

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×