Skip to content
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

Multi-column foreign keys #76

Closed
sqlalchemy-bot opened this issue Feb 24, 2006 · 5 comments
Closed

Multi-column foreign keys #76

sqlalchemy-bot opened this issue Feb 24, 2006 · 5 comments
Labels
feature high priority schema things related to the DDL related objects like Table, Column, CreateIndex, etc.
Milestone

Comments

@sqlalchemy-bot
Copy link
Collaborator

Migrated issue, originally created by Anonymous

(original reporter: rtl) SQLAlchemy already supports multi-column primary keys but doesn't support their 'mirror image', multi-column foreign keys. Ideally, the current foreign key syntax should be extended to support specifying multiple columns and the output will need to be in the format of a separate constraint:
e.g.

create table foo (
col1 integer primary key,
col2 integer primary key
)

create table foo2 (
col1 integer primary key,
foo_col1 integer,
foo_col2 integer
)
FOREIGN KEY( foo_col1, foo_col2) REFERENCES foo(col1, col2)

As foreign keys are a type of constraint, it would be useful to base them on a separately constructable Constraint object, which is needed in any case when two tables are mutually dependent on each other. Constraint, while handling create/drop functionality like anything else, could also apply foreign key objects to the relevant Column objects as well so you can specify them in place of the usual foreign key objects.

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • added labels: high priority

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • set milestone to "0.3.0"

@sqlalchemy-bot
Copy link
Collaborator Author

Anonymous wrote:

(original author: evan) I've written createable/droppable/reflectable foreign key constraint objects as part of Migrate. I didn't plan on multi-column foreign keys, but I have multi-column primary key constraints that behave similarly and work fine, so it wouldn't be much of a stretch. (I'm not volunteering to do the logic of attaching multi-column FKs to tables; just their creation/deletion in the database.)

Right now they're Postgres-only, though the plan is to support other DBs within the next couple weeks. I'll prepare a patch when that's done.

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

as of changeset:1726 this is implemented as ForeignKeyConstraint, PrimaryKeyConstraint which subclass Constraint. the ForeignKey object interacts with ForeignKeyConstraint so both exist if just one is specified. reflection also works with sqlite, postgres, mysql and oracle; not sure if ms-sql supports composite primary keys and havent touched firebird.

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot sqlalchemy-bot added schema things related to the DDL related objects like Table, Column, CreateIndex, etc. feature high priority labels Nov 27, 2018
@sqlalchemy-bot sqlalchemy-bot added this to the 0.3.0 milestone Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature high priority schema things related to the DDL related objects like Table, Column, CreateIndex, etc.
Projects
None yet
Development

No branches or pull requests

1 participant