What I’m trying to do:
I created an Anvil wep app some time ago. It works fine, THANKS to the Anvil team. It’s a pleasure to write code rather quickly, even so I’m still a beginner !
Now I must transfer the app from Anvil server to my work place, in order to keep the files in a safe place and be able to back them up regularly.
I have successfully installed the app on a headless Pi 5, Debian GNU/Linux 12. The database seems towork fine but postgresql doesn’t find its schema.
Details:
Here is the command line I ran, in a virtual environnemnt:
screen -dmS anvil_session_jmsite sudo /home/jmsite/venv/bin/anvil-app-server --config-file ‘/home/jmsite/jmmweb_config_file.yaml’
**Here is the config params for the Anvil app server ** :
jmmweb_config_file.yaml contains:
app: “/home/jmsite/jmmweb”
origin: “https://jmweb34.net”
auto-migrate: true
database: 'jdbc:postgresql://localhost/jmwb?user=jmarc&password=‘xxx’
secret:
pass_word: “xxxx”
smtp-host: “smtp.gmail.com”
smtp-port: 587
smtp-username: “jmmourlhou@gmail.com”
smtp-password: “xxx”
smtp-encryption: “starttls”
The installation went ok, I’ve tested the app from my phone and remote computer, especially add, read, delete rows from my products table. It’s ok.
But I encounter now a problem to transfer the real data from Anvil server to the local base:
What I’ve tried and what’s not working:
In fact I have tried to link the two twins (On anvil and on Pi5) apps together but had problem with
Then, from the Pi5, I wrote a python script and uplink to connect to anvil tables, it works. I get the rows from the ‘products’ table from Anvil, then open the local postgres DB ‘jmwb’ ok, but cannot write them in products table,
Code Sample:
# this is a formatted code snippet.
# paste your code between ```
# import anvil.tables as tables
from anvil.tables import app_tables
import anvil.server
anvil.server.connect("server_xxx")
rows = app_tables.products.search()
nb = len(rows)
anvil.server.disconnect
print(nb)
import psycopg2
# Connexion to the PGres base
try:
connection = psycopg2.connect(
dbname="jmwb",
user="jmarc",
password="xxxx",
host="localhost",
port="5432"
)
cursor = connection.cursor()
print("Successful Connexion to jmwb base")
# Request execution to read all rows from 'products' table
cursor.execute("SELECT * FROM products")
rows = cursor.fetchall()
for row in rows:
print(row)
except (Exception, psycopg2.Error) as error:
print("Error during the connexion to PostgreSQL", error)``
**the script output:**
Connecting to wss://anvil.works/uplink
Anvil websocket open
Connected to "jmweb34.net" as SERVER
500
Successful Connexion to jmwb base
**Error during the connexion to PostgreSQL relation "products" does not exist**
LINE 1: SELECT * FROM products
I can write, read, modify, delete products rows, using my local app installed on Pi5. I see that the anvil.yaml schema used by Anvil works fine. But Postgresql cannot find it or recognize it. How can I explain to postgres where to find it ?
I tried with CREATE SCHEMA IF NOT EXISTS schema_name;
I tested that, but to no avail.
Is it the right way and what is the name / place of that schema ?
In fact I have a second app with more than 10 different tables with many columns and links. It would be a headache to describe to postgres something that exists already, or download their CSV files....
You may have encountered that problem already and I must have missed something obvious along the way.
After several days ot testing and frustration, reading the forum issues, testing them, which help me to learn several other interesting points, I feel I really need a helping hand !
Thanks !