This project is archived and is in readonly mode.

#270 ✓wontfix
Mark A. Richman

Can't use :references in add_column

Reported by Mark A. Richman | May 28th, 2008 @ 07:40 PM

I have a User and an Address model, where User has_one :address. When creating the Address mode, I am planning for a polymorphic association for another model that also has_one :address. I need to use :references in a migration using add_column, just as I would using create_table.

I expected the following to work:

add_column :users, :addressable, :references, :polymorphic => true

here is the error:

== 20080526144501 CreateAddresses: migrating ==================================

-- create_table(:addresses)

-> 0.0040s

-- add_column(:users, :addressable, :references, {:polymorphic=>true})

rake aborted!

Workaround (reversed from schema.rb):

add_column :users, :addressable_id, :integer, :limit => 11

add_column :users, :addressable_type, :string



Comments and changes to this ticket

  • Darragh Curran

    Darragh Curran July 3rd, 2008 @ 11:03 AM

    • Tag cleared.

    What you think about change_table?

    change_table :users do |t|

    t.references :addressable, :polymorphic => true


    calling add column with expectation of having two columns sounds wrong to me - whereas using change table you get the same syntax you would have with create table

  • josh

    josh October 5th, 2008 @ 03:18 PM

    • State changed from “new” to “wontfix”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket