Comments (7)
Fixed in 0.9.0 by #92
from ormar.
That's not the case as ormar
uses only core part of the sqlalchemy
, so the one to create tables and build selects/inserts etc. So most of the issues for sa
won't help you with ormar
as they usually refer to orm
part (the one that you inherit from base etc.). You need to specifically search for core issues but even this might not help you as ormar
is built on top of this.
When you call get
or all
in ormar
you actually get the results back and later you delete
this particular instance. If you want to delete without loading there is delete
also in QuerySet
, i recently updated the docs in this regard.
Will check what's going on with the cascades.
Btw. Did you create the tables with ormar or connect to existing ones? Did you re-create/alter the tables after adding ondelete?
from ormar.
@collerek I tried to generate a new revision after adding ondelete
, but no changes were detected by alembic. I can try to do it from scratch and report back.
EDIT: seems to have resulted in the same thing - let me know if I can provide anything of use.
from ormar.
There is something wrong i investigate what exactly. In sqlite it sometimes does not create the flat. Can you check if the database structure in your case includes foreign keys definition? Or just the columns and no relations whatsoever?
I think it's something with the scope/locals/globals during resolution of foreign keys.
from ormar.
from ormar.
While not ideal, I solved this manually by adding the constraints to my Alembic script as such (still using the above example):
op.create_table(
"projects",
sa.Column("id", sa.CHAR(36), nullable=False),
sa.Column("created_date", sa.DateTime(), nullable=True),
sa.Column("updated_date", sa.DateTime(), nullable=True),
sa.Column("name", sa.String(length=256), nullable=False),
# <SNIP>
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"quotes",
sa.Column("id", sa.CHAR(36), nullable=False),
sa.Column("created_date", sa.DateTime(), nullable=True),
sa.Column("updated_date", sa.DateTime(), nullable=True),
sa.Column("project", sa.CHAR(36), nullable=True),
# <SNIP>
sa.PrimaryKeyConstraint("id"),
sa.ForeignKeyConstraint(
["project"], ["projects.id"], ondelete="CASCADE", onupdate="CASCADE"
),
)
That allows everything else to function as normal, and lets the DB take care of cascading the operation (can't speak to support for other backends, but this works for postgres).
from ormar.
Yeah, but that how it's supposed to look like out of the box :)
I found the bug it's related to deep-cloning sqlalchemy.Columns, will fix this and release new version soon.
Also will add names to foreign_keys so alembic can clearly identify constraints and not recreate them during consecutive runs.
from ormar.
Related Issues (20)
- Multiple reverse relations not working.
- Add `first_or_none`
- FastpAPI state has not database HOT 4
- How to configure alembic autogenerate with multiple model files HOT 5
- Error awaiting None
- Upgrade to SQLAlchemy 2.0 HOT 5
- Add SELECT DISTINCT feature to queryset
- Failing test: test_weakref_init
- Reverse relation not returned from get_pydantic
- Low performance on select_all() call HOT 1
- Nullable ForeignKey field does not get updated to null
- The future of ORMAR HOT 6
- Support specifying a table comment
- Please support pydantic-2.x HOT 3
- New release with the latest dependency upgrades HOT 2
- Unresolved attribute reference 'objects'
- Model field types and pyright
- v0.20.0 is released as stable instead of beta HOT 3
- Allow tables without primary key
- Allow Pydantic 1.10.13 to mitigate security risk
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 ormar.