Questions tagged [foreigner]

Foreigner was a Ruby gem that allowed management of foreign key constraints in migrations. It has been superseded by native functionality since Rails 4.2 was released, and is no longer developed.

Foreigner adds two methods to migrations.

add_foreign_key(from_table, to_table, options)
remove_foreign_key(from_table, to_table, options)

Github code repository

15 questions
37
votes
3 answers

foreigner - remove foreign key

I am trying to use mailboxer in my rails 4 app. A problem is arising when i try to deploy the db. The error occurs in creating the mailboxer conversations table, which has dependencies in notifications table. I am trying to remove the foreign key…
Mel
  • 2,481
  • 26
  • 113
  • 273
4
votes
1 answer

adding a foreign key in the table

I keep getting this exception: "SQLite3::SQLException: no such column: books.user_id: SELECT "books".* FROM "books" WHERE ("books".user_id = 4)". Which sounds like there is no user_id in the books table. So I just installed the Foreigner plugin and…
katie
  • 2,921
  • 8
  • 34
  • 51
4
votes
1 answer

How to work with tests and fixtures in a database with foreign key contraints in Rails?

I am using Rails 4.1 and PostgreSQL and I am using the foreigner gem to create foreign key constraints. But I am having some problems with fixtures. When I run: spring rake test I got errors like the following: ActiveRecord::InvalidForeignKey:…
user3153542
3
votes
3 answers

Why would someone use the gem foreigner?

This is most likely a noob question since people use this gem and a lot of people love it, but I don't get the purpose. I'm looking at a project and its been used here many times in places such as t.references :foreign_key_table_name , :foreign_key…
GiH
  • 14,006
  • 13
  • 43
  • 56
2
votes
3 answers

How can I prevent Rails from "pluralizing" a column name?

I'm using dwilkie's foreigner plugin for rails. I have a table creation statement that looks like: create_table "agents_games", :force => true, :id => false do |t| t.references :agents, :column => :agent_id, :foreign_key => true, :null =>…
Mike
  • 23,892
  • 18
  • 70
  • 90
1
vote
0 answers

rake aborted! NoMethodError: undefined method `alias_method_chain' for ActiveRecord::SchemaDumper:Class

when i added the foreigner gem in gemfile this occur and i am upgrading rails 4.1 to 6.1: any solution anyone have fast post otherwise you can mail to…
1
vote
1 answer

How does the foreigner gem work?

I'm looking at the foreigner gem and trying to create some foreign keys. However, the gems documentation says that you should create your foreign keys like this `add_foreign_key(from_table, to_table, options) but when I do that, it seems like it…
GiH
  • 14,006
  • 13
  • 43
  • 56
0
votes
2 answers

Is it mandatory to separately remove the foreign keys / indexes if you are planning to drop the table

Is it mandatory to separately remove the foreign keys / indexes, if you are planning to drop the table. Since dropping the table seems to be removing foreign keys / indexes. I am using this gem http://github.com/matthuhiggins/foreigner to remove the…
priya
  • 24,861
  • 26
  • 62
  • 81
0
votes
2 answers

Ruby on Rails Foreigner plugin not working for SQL Server

Well, now that I've finally got my stupid ODBC stuff configured, I took a schema.rb file that I dumped from a Postgres database and did a db:schema:load on it in a Rails project configured for SQL Server. Well, it sets up all the schema in the SQL…
Earlz
  • 62,085
  • 98
  • 303
  • 499
0
votes
1 answer

Ruby on Rails - Foreign Keys (foreigner gem)

I'm new to RoR so don't be surprised with possible dumm things I may say... sorry in advance... I'm trying to create foreign keys constrainsts between two models "Addendum" and "Contract" the ActiveRecord is now like this class Addendum <…
NunoRibeiro
  • 511
  • 2
  • 7
  • 22
0
votes
1 answer

specifying customer foreignkey column name using foreigner gem

I have 2 models, employee and user with a has_one, belongs_to relationship. The user table has a 'login' column which needs to only be the 'emp_id' value from the employee table. I tried to capture this relationship with the below migration: …
0
votes
1 answer

When running migrations on Heroku, I get PG::Error: ERROR: relation "member1_id" does not exist

Locally, my migrations are fine (although I'm using SQLite. Will switch to postgresql on development asap). After resetting the database on Heroku with heroku pg:reset DATABASE I ran heroku run rake db:migrate But I am getting the following…
Eric Baldwin
  • 3,341
  • 10
  • 31
  • 71
0
votes
1 answer

SQLite migration removes 'add_index' and 'add_foreign_key' from schema.rb file

I use SQLite3 and MySQL on the same Rails project but on two different computers. I noticed that the schema.rb which is generated when I run all migrations looks different for both environments. When I run the migrations in the SQLite3 environment…
JJD
  • 50,076
  • 60
  • 203
  • 339
0
votes
1 answer

Rails Foreigner Plugin

My user table should have a role_id ( not added in my table yet ) My role table has uses the default primary id: id I am currently trying to use the foreigner plugin where it looks like ... class AddForeignKeyToUserFromRole <…
freedom
  • 751
  • 1
  • 10
  • 20
0
votes
1 answer

Rails Foreigner: foreign key constraints for "test" DB using MySQL

I'm trying to use Foreigner to enable foreign key constraints in Rails. It's working on my development DB, but I get the following error when I try to run my tests: Errors running test:units! #
George Armhold
  • 30,824
  • 50
  • 153
  • 232