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.