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

Rails 4.2, MySQL: cannot use 't.references' in migration #629

Closed
bulzak opened this issue Mar 11, 2015 · 1 comment
Closed

Rails 4.2, MySQL: cannot use 't.references' in migration #629

bulzak opened this issue Mar 11, 2015 · 1 comment

Comments

@bulzak
Copy link

bulzak commented Mar 11, 2015

So I generated a Rails migration using the 'references' keyword to create the association between model First and Second. I called:

rails g model second name:string first:references

And I got this:

class CreateSeconds < ActiveRecord::Migration
  def change
    create_table :seconds do |t|
      t.string :name
      t.references :first, index: true

      t.timestamps null: false
    end
    add_foreign_key :seconds, :firsts
  end
end

It fails like so:

command: rake db:migrate
== 20150311070101 CreateSeconds: migrating ====================================
-- create_table(:seconds)
#<Class:0x3e73138a>: An error has occurred, all later migrations canceled:

Index name 'index_seconds_on_first_id' on table 'seconds' already exists

It fails before the add_foreign_key call, complaining that the Index name 'index_seconds_on_first_id' on table 'seconds' already exists. The current walkaround is to remove the t.references call and replace it by add_reference :seconds, :first, index: true outside of create_table. So what is going on, why is t.references creating the index twice?

Also, the add_foreign_key method doesn't do anything at the moment.

akarazniewicz pushed a commit to akarazniewicz/activerecord-jdbc-adapter that referenced this issue Mar 15, 2015
@kares
Copy link
Member

kares commented Apr 3, 2015

should be fixed now on 1-3-stable with #631 in place ... feel free to re-open if not, thanks!

@kares kares closed this as completed Apr 3, 2015
kares added a commit that referenced this issue Jun 12, 2015
kares added a commit that referenced this issue Jun 13, 2015
* 1-3-stable: (43 commits)
  one last place of missed shared AR4x constants refactoring (thanks travis-ci!)
  missed places for updating to using shared AR4x constants
  use the (shared) AR4x constants in PostgreSQL adapter
  move AR4x constants to (top-level) ArJdbc
  adapt schema dump test on AR 4.2 ... *t.string \"id\", limit: 255, null: false* now
  [mysql] bulk compatibility with AR 4.2 - all _sql helper accept an options (hash)
  [mysql] back-port case sensitive/insensitive comparison
  [mysql] handle precision for datetimes when doing type_to_sql (AR 4.2 compat)
  adjust foreign key test introduced in #629 (was failing with MRI under AR 4.2.1)
  [mysql] schema creation compatibility with AR 4.2 (drop FK & temporayr tables)
  [mysql] validate_index_length! when available
  [mysql] foreign key support based on AR 4.2 (fixes #656)
  review foreign_key support in Postgres adapter (extract helper should be private)
  AR 4.2 valid_type? method for all
  finish up the foreign key test - more asserts less puts
  [postgres] drop_table backported to support `:force => :cascade` option
  [postgres] foreign_key support back-ported from AR 4.2 (fixes #656)
  [postgres] primary_key compatibility with latest AR
  export `open?` and ("raw") `close` helpers on the JDBC connection side
  alias jdbc_connection active? as valid? (just so its clearer on what it does)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants