Comments (6)
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.
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.
@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.
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.
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.
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)
- In the automatically generated model file, the self-incrementing id field does not have the `autoincrement=true` attribute HOT 5
- codegen.py:390: SAWarning: Cannot correctly sort tables HOT 4
- Code generation for PostgreSQL composite types
- Option --generator only works in pre-release package HOT 3
- fix function name in codegen.py for python v3.11 HOT 1
- Nullable relationships require `Optional`
- Error in Generated SQLAlchemy Model for CHAR Column HOT 2
- Constraints Issues with Oracle HOT 1
- Unable to install `sqlacodegen` due to ioutdated PyPI release HOT 2
- Add support for multiple databases binding
- Entry point documentation
- Enhancement: Add Support for pgvector extension HOT 2
- SQLModel codegen produces syntax errors HOT 4
- Syntax Error in 3.0.0rc3 HOT 5
- No poetry package which supports SQLAlchemy 2.0 HOT 5
- AssertionError: TypeDecorator implementations require a class-level variable 'impl' HOT 14
- sqlalchemy.exc.OperationalError HOT 5
- Database URL is split on & HOT 1
- No module named 'pkg_resources'
- ImportError: cannot import name 'ArgSpec' from 'inspect' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlacodegen.