-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bad foreign_keys parameter for self-referencing table #233
Comments
IIRC this is fixed in master. Would you mind trying with that? |
On master, DDL: CREATE TABLE document(
id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(),
image_id UUID
);
ALTER TABLE document ADD CONSTRAINT image_fk
FOREIGN KEY (image_id)
REFERENCES document(id) ON DELETE CASCADE; generated: @mapper_registry.mapped
@dataclass
class Document:
__tablename__ = 'document'
__table_args__ = (
ForeignKeyConstraint(['image_id'], ['document.id'], ondelete='CASCADE', name='image_fk'),
PrimaryKeyConstraint('id', name='document_pkey')
)
__sa_dataclass_metadata_key__ = 'sa'
id: str = field(metadata={'sa': Column(UUID, server_default=text('gen_random_uuid()'))})
image_id: Optional[str] = field(default=None, metadata={'sa': Column(UUID)})
image: Optional[Document] = field(default=None, metadata={'sa': relationship('Document', remote_side=[id], back_populates='image_reverse')})
image_reverse: List[Document] = field(default_factory=list, metadata={'sa': relationship('Document', remote_side=[image_id], back_populates='image')}) error:
|
I think in my original message I was using master too, but there were other fields and tables. |
Issue is gone at least for declarative mode with SQLAlchemy 2 |
@agronholm I generated my models using version 3.0.0rc2 which I believe has the fix in for this issue but i'm getting and error with this model
Error:
|
Could you at least update to the latest pre-release first? |
The latest version drops support for SQLAlchemy 1.x which is what we're using. |
Well, then I'm afraid I can't help you. I have extremely little time to devote to this project in the first place, let alone for old versions of it. |
DDL in postgres:
dataclass generated:
SQLAlchemy error:
I think the argument should be
"[Document.image_id]"
.The text was updated successfully, but these errors were encountered: