Comments (8)
Hmm.. it's difficult for me to debug this so here are some questions:
Do these same foreign keys show up when doing a "rake db:structure:dump"?
Pick one of these problematic tables and run the big query inside https://github.com/matthuhiggins/foreigner/blob/master/lib/foreigner/connection_adapters/postgresql_adapter.rb
It's going to be one of two problems: Your database actually has duplicates, or the sql query to read the foreign keys is wrong.
from foreigner.
@matthuhiggins, the dump is fine:
--- -- Name: reservation_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY inventory_request_reservation_items ADD CONSTRAINT reservation_id_fk FOREIGN KEY (reservation_id) REFERENCES inventory_request_reservations(id);
But query seems wrong:
SELECT tc.constraint_name as name ,ccu.table_name as to_table ,ccu.column_name as primary_key ,kcu.column_name as column ,rc.delete_rule as dependency FROM information_schema.table_constraints tc JOIN information_schema.key_column_usage kcu USING (constraint_catalog, constraint_schema, constraint_name) JOIN information_schema.referential_constraints rc USING (constraint_catalog, constraint_schema, constraint_name) JOIN information_schema.constraint_column_usage ccu USING (constraint_catalog, constraint_schema, constraint_name) WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.constraint_catalog = '...' AND tc.table_name = 'inventory_request_reservation_list_items' AND tc.table_schema = ANY (current_schemas(false)); name | to_table | primary_key | column | dependency ------------------------+-------------------------------------+-------------+---------------------+------------ reservation_id_fk | inventory_request_reservations | id | reservation_id | NO ACTION reservation_id_fk | inventory_request_reservations | id | reservation_id | NO ACTION reservation_id_fk | inventory_request_reservations | id | reservation_id | NO ACTION reservation_id_fk | inventory_request_reservations | id | reservation_id | NO ACTION reservation_id_fk | inventory_request_reservations | id | reservation_id | NO ACTION reservation_id_fk | inventory_request_reservations | id | reservation_id | NO ACTION reservation_id_fk | inventory_request_reservations | id | reservation_id | NO ACTION reservation_id_fk | inventory_request_reservations | id | reservation_id | NO ACTION reservation_item_id_fk | inventory_request_reservation_items | id | reservation_item_id | NO ACTION list_id_fk | inventory_request_reservation_lists | id | list_id | NO ACTION (10 rows)
I don't know how we can fix that. I'm looking the database but dump is generated correctly.
Looks like a issue with query, not my database.
from foreigner.
The query is wrong. I'm working in a fix :)
from foreigner.
That would be sweet. I am using postgres very lightly and have not seen this problem.
from foreigner.
The pull request fix an issue with repeated names for different constraints :)
from foreigner.
I like this query a lot more than the existing one!
Is pg_constraint defined per database? For example, if there are two projects running on the same postgres server, will this query retrieve the foreign keys from both databases, or just the one for the connection.
Also, do they need to be left joins?
from foreigner.
Yes, each database has your pg_catalog.pg_constraints table.
And no, the left join could be changed to join, makes more sense.
from foreigner.
Closing. Pull request was accepted :)
from foreigner.
Related Issues (20)
- Minor fix in documentation HOT 1
- Code for version 1.6.0 HOT 1
- rake test - fails uninitialized constant Foreigner::ConnectionAdapters (NameError) HOT 1
- Support for Postgres NOT VALID options for foreign key constraints HOT 1
- Foreigner doesn't work with Padrino 0.12.0 HOT 1
- Doesn't seem to do much for me (SQLite3)? HOT 7
- Really only supports the "postgres" and not "postgresql" ('pg' Gem) adapter? HOT 2
- Support for renaming foreign keys
- Can't rename a table after adding a foreign_key with custom name [mysql2] HOT 2
- options: "deferrable" missing in schema.rb HOT 5
- Undefined method from_table HOT 3
- posgresql primary key HOT 3
- During migration Foreigher throw NoMethodError HOT 10
- Add support for columns other than `other_table_id` HOT 1
- options: "," HOT 4
- Rails 4.1.9: During migration Foreigher throw undefined method `add_foreign_key' for #<ActiveRecord::Schema:... HOT 29
- Foreigner dumps errenous schema if using Apartment gem
- Readme addition: plans for rails 4.2 onwards HOT 4
- Unique index with foreign key HOT 1
- rake aborted! NoMethodError: undefined method `alias_method_chain' for ActiveRecord::SchemaDumper:Class
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 foreigner.