[sqlalchemy] Re: Connection error
Have you confirmed that you can connect to 127.0.0.1 at port 5432 using psql? On my development system, I normally use a local (UNIX domain) socket, which is libpq's default behavior. When I run "psql -h 127.0.0.1", I get the following error: psql: could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432? On Tuesday, June 15, 2021 at 1:06:23 PM UTC-4 Ryan Bandler wrote: > Hello everyone, > > I am a first-time SQLalchemy user planning on using SQLalchemy on a new > project. We already have an established postgres database (currently still > on localhost) which I do not want to handwrite the SQLalchemy model for. So > I am planning to use sqlacodegen. Unfortunately, sqlacodegen is giving me: > > sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not > connect to server: Connection refused > Is the server running on host "localhost" (127.0.0.1) and accepting > TCP/IP connections on port 5432? > > My systems at work are very restrictive, but I was able to gain > permissions to the postgres config files and edited them to allow all TCP > connections. I restarted the postgres service and I am still experiencing > this error. I dont understand why this is happening, because it seems to be > an error coming from psycopg2 being called in sqlalchemy, and i have ever > had any issues connecting to the DB with psycopg2 before. > > If anyone has any experience with sqlacodegen, any help would be much > appreciated!! > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/3179b853-7b73-462e-85c7-5ef3c4995f17n%40googlegroups.com.
[sqlalchemy] Proper date abstraction in case statement
Hi, I have a case statement that should compare just the date for equality, however the code considers the time as well: Model.dateCol == func.sysdate() Another issue is this is a DATE field (therefore datetime) in an Oracle database in one environment and a DATE field (actual date) in an MSSQL database in another environment. Would the correct way to achieve this comparison across both abstractions be: cast(Model.dateCol, Date) == cast(func.sysdate(), Date) Thanks, jlc -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/15a73018-1b07-453b-b545-d4aad6687df4n%40googlegroups.com.
Re: [sqlalchemy] Connection error
Hi Rich, I appreciate the response. I understand how the structure of the SA model works, it really is quite simple. My question was about an error while using a third party tool called sqlacodegen, which is a tool which connects to a DB and automatically generates the SA model. I am using this tool because I have many tables with lots of columns and I dont like typing boilerplate code when I dont have to. My question was not about SA itself or how writing the model works ,but about this error I am experiencing with this generator tool. I appreciate the response though! Best, Ryan On Tuesday, June 15, 2021 at 1:13:15 PM UTC-4 rshe...@appl-ecosys.com wrote: > On Tue, 15 Jun 2021, Ryan Bandler wrote: > > > I am a first-time SQLalchemy user planning on using SQLalchemy on a new > > project. > > Ryan, > > I started to learn SA long ago, but put off the project. Now I'm starting > over again with much to learn. > > > We already have an established postgres database (currently still on > > localhost) which I do not want to handwrite the SQLalchemy model for. So > I > > am planning to use sqlacodegen. Unfortunately, sqlacodegen is giving me: > > My postgres databases exist and have data. I used the short version of > declarative models; don't know if the concept and syntax still holds for SA > version 1.4.x > > For one project the model.py file is: > """ > This is the SQLAlchemy declarative mapping python classes to postgres > tables for the business tracker. > """ > > from sqlalchemy import create_engine > from sqlalchemy.ext.automap import automap_base > from sqlalchemy.ext.declarative import declarative_base > from sqlalchemy import Column, Unicode, Integer, String, Date > from sqlalchemy.orm import sessionmaker > from sqlalchemy import ForeignKey > from sqlalchemy.orm import relationship > from sqlalchemy import CheckConstraint > from sqlalchemy.orm import Session > from sqlalchemy.dialects import postgresql > > """Base = declarative_base()""" > Base = automap_base() > > engine = create_engine('postgresql+psycopg2:///bustrac') > > # reflect the tables > Base.prepare(engine, reflect=True) > > State = postgresql.Enum('AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', > 'DC', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', > 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', > 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', > 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY', 'AB', 'BC', 'MB', 'NB', 'NL', > 'NT', 'NS', 'NU', 'ON', 'PE', 'QC', 'SK', 'YT', name='states') > > Industries = Base.classes.industries > Status = Base.classes.status > StatusTypes = Base.classes.statusTypes > ActivityTypes = Base.classes.activityTypes > Organizations = Base.classes.organizations > Locations = Base.classes.locations > People = Base.classes.people > Activities = Base.classes.activities > Projects = Base.classes.projects > > Base.metadata.create_all(engine) > > Session = sessionmaker(bind=engine) > > HTH, > > Rich > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/2d5750de-c490-4757-8042-570ae72591d0n%40googlegroups.com.
Re: [sqlalchemy] Connection error
On Tue, 15 Jun 2021, Ryan Bandler wrote: I am a first-time SQLalchemy user planning on using SQLalchemy on a new project. Ryan, I started to learn SA long ago, but put off the project. Now I'm starting over again with much to learn. We already have an established postgres database (currently still on localhost) which I do not want to handwrite the SQLalchemy model for. So I am planning to use sqlacodegen. Unfortunately, sqlacodegen is giving me: My postgres databases exist and have data. I used the short version of declarative models; don't know if the concept and syntax still holds for SA version 1.4.x For one project the model.py file is: """ This is the SQLAlchemy declarative mapping python classes to postgres tables for the business tracker. """ from sqlalchemy import create_engine from sqlalchemy.ext.automap import automap_base from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Unicode, Integer, String, Date from sqlalchemy.orm import sessionmaker from sqlalchemy import ForeignKey from sqlalchemy.orm import relationship from sqlalchemy import CheckConstraint from sqlalchemy.orm import Session from sqlalchemy.dialects import postgresql """Base = declarative_base()""" Base = automap_base() engine = create_engine('postgresql+psycopg2:///bustrac') # reflect the tables Base.prepare(engine, reflect=True) State = postgresql.Enum('AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY', 'AB', 'BC', 'MB', 'NB', 'NL', 'NT', 'NS', 'NU', 'ON', 'PE', 'QC', 'SK', 'YT', name='states') Industries = Base.classes.industries Status = Base.classes.status StatusTypes = Base.classes.statusTypes ActivityTypes = Base.classes.activityTypes Organizations = Base.classes.organizations Locations = Base.classes.locations People = Base.classes.people Activities = Base.classes.activities Projects = Base.classes.projects Base.metadata.create_all(engine) Session = sessionmaker(bind=engine) HTH, Rich -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/alpine.LNX.2.20.2106151009500.3763%40salmo.appl-ecosys.com.
[sqlalchemy] Connection error
Hello everyone, I am a first-time SQLalchemy user planning on using SQLalchemy on a new project. We already have an established postgres database (currently still on localhost) which I do not want to handwrite the SQLalchemy model for. So I am planning to use sqlacodegen. Unfortunately, sqlacodegen is giving me: sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? My systems at work are very restrictive, but I was able to gain permissions to the postgres config files and edited them to allow all TCP connections. I restarted the postgres service and I am still experiencing this error. I dont understand why this is happening, because it seems to be an error coming from psycopg2 being called in sqlalchemy, and i have ever had any issues connecting to the DB with psycopg2 before. If anyone has any experience with sqlacodegen, any help would be much appreciated!! -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/bd0c54b5-8057-46eb-adec-411a79c52911n%40googlegroups.com.
Re: [sqlalchemy] checking in
You can see the archives at https://groups.google.com/g/sqlalchemy to get an idea of the traffic. Simon On Mon, Jun 14, 2021 at 10:25 PM Rich Shepard wrote: > > I've not worked with SQLAlchemy for several years but now want to use it in > a couple of applications. I've not seen messages on this maillist for a very > long time so I tried subscribing and learned that I'm still subscribed. > > Am I the only one on this list now? > > If not I wonder why messages aren't arriving in my INBOX. > > Rich > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/alpine.LNX.2.20.2106141423470.11603%40salmo.appl-ecosys.com. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CAFHwexc2WRWhb3LZEymfeHypSYv%3DeOQOmC5%2BtNdm%2B1x3Xw%2BBFA%40mail.gmail.com.