Coder Social home page Coder Social logo

Comments (6)

agronholm avatar agronholm commented on June 3, 2024 1

SQLAlchemy ORM classes do not work without a primary key definition: https://docs.sqlalchemy.org/en/14/faq/ormconfiguration.html#how-do-i-map-a-table-that-has-no-primary-key
You do know that you can use a Session to query plain tables too?

from sqlacodegen.

agronholm avatar agronholm commented on June 3, 2024

For what purpose would you want association tables to be classes instead of interim tables in many-to-many relationships? As for the other case, tables without a pk column cannot be classes anyway.

from sqlacodegen.

thirdeye-hichame avatar thirdeye-hichame commented on June 3, 2024

@agronholm , thanks for the response. I wanted to generate classes similar to here

Since it was 5 months ago I don't have the exact specific use case any more but I know I wanted to insert objects into an interim table with a composite primary key PRIMARY KEY(parent_id, children_id)

To solve this problem I forked agronholm/sqlacodegen and added the argument myself.

from sqlacodegen.

agronholm avatar agronholm commented on June 3, 2024

I guess I could add something like --nomanytomany which would skip the detection of association tables, in which case they would be rendered as classes instead of Tables (assuming they have primary keys). Would this be acceptable?

from sqlacodegen.

petergok avatar petergok commented on June 3, 2024

This would be very useful for us to be able to generate classes we can query for tables that don't have a primary key. Here's a quick proposed solution with an --onlyclasses argument: https://github.com/perpetua1/sqlacodegen

from sqlacodegen.

petergok avatar petergok commented on June 3, 2024

You're right, we just tried it and it didn't work with class-based tables. The problem is that we recently removed the primary key and had a lot of code that accessed columns through Class.column rather than Class.c.column.

We'll see if we can get around this but this something within sqlalchemy itself rather than this library.

from sqlacodegen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.