title: Flask-SQLAlchemy AttributeError: can't set attribute
body: <p>I try to create a database and put an article table in routes.py's /articles/&lt;article_name&gt; route but it gives me AttributeError: can't set attribute. I looked up other sources for a solution but they seemed irrelevant. Error occurs when create_all(), add(), commit() are used.</p>
  <p>models.py</p>
  <pre><code>from files import db
  from datetime import datetime
  
  class Article(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      title = db.Column(db.String(100), nullable=False,unique=True)
      article_content = db.Column(db.Text)
      date = db.Column(db.DateTime,default=datetime.utcnow)
      abstract = db.Column(db.String(150))
      comments = db.relationship(&quot;Comment&quot;, backref=&quot;article&quot;, lazy = True)
  
  class User(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      user_name = db.Column(db.String(30), unique=True, nullable=False)
      password = db.Column(db.String(30), nullable=False)
      comments = db.relationship(&quot;Comment&quot;, backref=&quot;user&quot;, lazy = True)
  
  class Comment(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      user_comment = db.Column(db.String(200), nullable=False)
      user_id = db.Column(db.Integer, db.ForeignKey(&quot;user.id&quot;))
      article_id = db.Column(db.Integer, db.ForeignKey(&quot;article.id&quot;))
  </code></pre>
  <p><strong>init</strong>.py</p>
  <pre><code>from flask import Flask
  from flask_sqlalchemy import SQLAlchemy
  
  app = Flask(__name__)
  app.config['SECRET_KEY'] = ''
  app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
  db = SQLAlchemy(app)
  
  from files import routes
  </code></pre>
  <p>routes.py</p>
  <pre><code>from files import app, db
  from flask import render_template
  from files.models import Article
  from files.forms import RegisterForm, LoginForm
  
  @app.route('/')
  @app.route('/main')
  @app.route('/home')
  def home():
      return render_template(&quot;home.html&quot;)
  
  @app.route('/articles/&lt;article_name&gt;') # dynamic route
  def article(article_name):
      db.create_all()
  
      article_ = Article(title = article_name, article_content = &quot;article&quot;, abstract = &quot;ndng&quot;)
  
      db.session.add(article_)
      db.session.commit()
      return render_template(&quot;article.html&quot;, article_name=article_name)
  
  @app.route('/articles')
  def articles():
      return render_template(&quot;articles.html&quot;)
  
  @app.route('/register')
  def register():
      form = RegisterForm()
      return render_template(&quot;register.html&quot;, form = form)
  
  
  @app.route('/login')
  def login():
      form = LoginForm()
      return render_template(&quot;login.html&quot;, form = form)
  </code></pre>