R
Railway•15mo ago
MilanK

postgresql

What changes do I need to make in the fastapi demo app to be able to access a postgresql? Both are from Railway templates and running in the production environment. I'm novice to all this.
18 Replies
Percy
Percy•15mo ago
Project ID: 3ffb43c3-27a4-47ba-b079-79313c5ebe25
MilanK
MilanK•15mo ago
3ffb43c3-27a4-47ba-b079-79313c5ebe25
Brody
Brody•15mo ago
add a postgre database plugin to your project setup the variable references to the database in your service ust use your postgre python package of your choosing and connect using the environment variables
MilanK
MilanK•15mo ago
How do I add a postgre database plugin to a project? I have created variable references Sample code how to fetch data from the postgre database?
Brody
Brody•15mo ago
once you are in the project you click the plus button in the top right then once the database is added, setup the variable references in your service that will be using the database https://docs.railway.app/develop/variables#reference-variables as for sample code, you'll have to read some tutorials
MilanK
MilanK•15mo ago
Ah yes I have added the postgresql, do you have a tutorial how to initialize it from requirements.txt and main.py so it can be used in the code? I looked in your doc library but could not find any suitable sample.
Brody
Brody•15mo ago
that's more of a question you answer by reading or watching tutorials
MilanK
MilanK•15mo ago
ok, do you know how I can get professional services to help me out - do you offer a service like this?
Brody
Brody•15mo ago
these help threads are intended for questions about the platform. I'm sure there's some great YouTube videos on how to query postgre from python that you could watch!
MilanK
MilanK•15mo ago
ok
Brody
Brody•15mo ago
if you have any questions involving railway or issues with railway, feel free to ask those here
MilanK
MilanK•15mo ago
I can't figure out why pip command does not work in my code - it works in my local development: File "main.py", line 1 pip install mysqlclient ^ @Brody is the syntax different in railway for pip? if so how do I install mysqlclient in the main.py?
Brody
Brody•15mo ago
please watch this video https://www.youtube.com/watch?v=oLlT6c6jA-M #🛂|readme #5 in your original question you ask how to use postgre, but now you are trying to install a mysql package, i can recommend you stick with postgre
MilanK
MilanK•15mo ago
Ok I got it to work with postgre by including it in the requirements.txt But I think there is some issue with MySQL - it did not even work on the Query UI interface when I run Select * from Customers - page crashes and shows "Application error: a client-side exception has occurred (see the browser console for more information)." Also when I added mysqlclient==2.1.1 to the requirements.txt it also throws build errors.
Brody
Brody•15mo ago
1. postgre and mysql are two different things. 2. please don't rely on the data tab of the database plugins
MilanK
MilanK•15mo ago
1. yes I'm aware, I have worked with both of them previously 2. ok noted Thanks for your help @Brody
Brody
Brody•15mo ago
no problem!