I have set the TRYTON_DATABASE configuration to 'database', but it seems like the application cannot find the database file at the specified location (/home/username/db/database.sqlite).
Here is the relevant part of my Flask app:
from flask import Flask, request, jsonify
from trytond.pool import Pool
from trytond.config import config
from trytond.transaction import Transaction
from flask_tryton import Tryton
app = Flask(__name__)
app.config['TRYTON_DATABASE'] = 'database'
tryton = Tryton(app, configure_jinja=True)
config.update_etc('/home/username/project/backoffice/tryton/trytond.conf')
Pool.start()
@app.before_request
def log_request():
print(f"=== Request masuk: {request.method} {request.path} ===")
@app.route('/')
@tryton.transaction()
def hello():
user, = User.search([('login', '=', 'admin')])
return '%s, Hello World!' % user.name
I have verified that the database file doesn’t exist at /home/username/db/database.sqlite. What are the recommended steps to either create the database or ensure that the application connects to the correct database?
Additionally, if the database file needs to be created, what would be the correct procedure for setting it up with Tryton?
You need to set the environment variable TRYOND_CONFIG with the path of your configuration file. This way the flask server will read the settings from this file and connect to your postgres database. Something like:
$ TRYTOND_CONFIG=/home/username/project/backoffice/tryton/trytond.conf flask run
Otherwise the flask server uses the default database settings and tries to connect to a sqlite database.