Минимально рабочий вариант:
from datetime import datetime
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///blog.db'
app.config['SQLALCHEMY_BINDS'] = {
'messages': 'sqlite:///message.db'
}
db = SQLAlchemy(app)
class Article(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False)
intro = db.Column(db.String(300), nullable=False)
text = db.Column(db.Text, nullable=False)
date = db.Column(db.DateTime, default=datetime.utcnow)
def __repr__(self):
return '<Article %r>' % self.id
class Message(db.Model):
__bind_key__ = 'messages'
id = db.Column(db.Integer, primary_key=True)
Name = db.Column(db.Text, nullable=False)
Surname = db.Column(db.Text, nullable=False)
text = db.Column(db.Text, nullable=False)
date = db.Column(db.DateTime, default=datetime.utcnow)
def __repr__(self):
return '<Message %r>' % self.Name
@app.route('/add_message')
def add_message():
message = Message(Name='name', Surname='surname', text='foo')
db.session.add(message)
db.session.commit()
return 'True'
db.create_all()
db.create_all(bind='messages')
if __name__ == '__main__':
app.run(debug=1)