Skip to content

sqlalchemy2ormar - failed to create ormar class #1

Description

@avico78

Describe the bug
I create tables where tables actually define as ormar class in program ,.
once tables created - verified them in DB.
Also manage to fetch/insert data with the models,

Tried pull the ormar class using the sqlalchemy2ormar:

from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine
import ormar

Base = automap_base()

# engine, suppose it has tables setup
engine = create_engine("postgresql://admin:admin@192.168.1.112:5432/customer_trg")

# reflect the tables
Base.prepare(engine, reflect=True)

# translate whole db
ormar_models = [sqlalchemy_to_ormar(sqlalchemymodel, database=database, metadata=metadata) for sqlalchemymodel in Base.classes]

getting:

   raise sa_exc.ArgumentError(
sqlalchemy.exc.ArgumentError: WARNING: when configuring property 'customer' on mapped class subscriber->subscriber, column 'customer' conflicts with property '<RelationshipProperty at 0x48b32e8; customer>'. To resolve this, map the column to the class under a different name in the 'properties' dictionary.  Or, to remove all awareness of the column entirely (including its availability as a foreign key), use the 'include_properties' or 'exclude_properties' mapper arguments to control specifically which table columns get mapped

To Reproduce
Create tables in DB:

-- Table: public.customer

-- DROP TABLE public.customer;

CREATE TABLE public.customer
(
    creation_date timestamp without time zone,
    modification_date timestamp without time zone,
    id integer NOT NULL DEFAULT nextval('customer_id_seq'::regclass),
    customer_no integer,
    customer_status character varying(100) COLLATE pg_catalog."default",
    first_name character varying(100) COLLATE pg_catalog."default",
    last_name character varying(100) COLLATE pg_catalog."default",
    email character varying(60) COLLATE pg_catalog."default",
    pin_code text COLLATE pg_catalog."default",
    CONSTRAINT customer_pkey PRIMARY KEY (id),
    CONSTRAINT uc_customer_creation_date_modification_date_customer_no UNIQUE (creation_date, modification_date, customer_no)
)

TABLESPACE pg_default;

ALTER TABLE public.customer
    OWNER to admin;

-- Table: public.subscriber

-- DROP TABLE public.subscriber;

CREATE TABLE public.subscriber
(
    creation_date timestamp without time zone,
    modification_date timestamp without time zone,
    id integer NOT NULL DEFAULT nextval('subscriber_id_seq'::regclass),
    subscriber_no integer,
    is_active boolean,
    customer integer,
    CONSTRAINT subscriber_pkey PRIMARY KEY (id),
    CONSTRAINT fk_subscriber_customer_id_customer FOREIGN KEY (customer)
        REFERENCES public.customer (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE public.subscriber
    OWNER to admin;

Expected behavior
Expect to get ormar Class

Versions (please complete the following information):

  • Database backend used : postgress
    Python version 3.8
    ormar 0.10.5
    sqlalchemy-to-ormar 0.0.1

Additional context

I double check with other tool there's no DB issue ,
the tool provide the sqlalchemy our of DB :

sqlacodegen postgresql://admin:admin@192.168.1.112:5432/customer_trg


class Customer(Base):
    __tablename__ = 'customer'
    __table_args__ = (
        UniqueConstraint('creation_date', 'modification_date', 'customer_no'),
    )

    creation_date = Column(DateTime)
    modification_date = Column(DateTime)
    id = Column(Integer, primary_key=True, server_default=text("nextval('customer_id_seq'::regclass)"))
    customer_no = Column(Integer)
    customer_status = Column(String(100))
    first_name = Column(String(100))
    last_name = Column(String(100))
    email = Column(String(60))
    pin_code = Column(Text)




class Subscriber(Base):
    __tablename__ = 'subscriber'

    creation_date = Column(DateTime)
    modification_date = Column(DateTime)
    id = Column(Integer, primary_key=True, server_default=text("nextval('subscriber_id_seq'::regclass)"))
    subscriber_no = Column(Integer)
    is_active = Column(Boolean)
    customer = Column(ForeignKey('customer.id'))

    customer1 = relationship('Customer')

Would appreciate an instruction how run the tool on specific list ,

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions