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

ActiveRecord::Migration table.references() ignores ActiveRecord::Base.pluralize_table_names = false #19643

Closed
erikj opened this issue Apr 3, 2015 · 0 comments · Fixed by #19652
Assignees
Milestone

Comments

@erikj
Copy link
Contributor

erikj commented Apr 3, 2015

It appears that in Rails / ActiveRecord 4.2.1, that the references column "type" ignores ActiveRecord::Base.pluralize_table_names or doesn't work as expected when configured to false:

$ grep plural config/environment.rb
ActiveRecord::Base.pluralize_table_names = false
$ rails generate model foo
      invoke  active_record
      create    db/migrate/015_create_foo.rb
      create    app/models/foo.rb
      invoke    minitest
      create      test/models/foo_test.rb
      create      test/fixtures/foos.yml

$ rails generate model bar foo:references
      invoke  active_record
      create    db/migrate/016_create_bar.rb
      create    app/models/bar.rb
      invoke    minitest
      create      test/models/bar_test.rb
      create      test/fixtures/bars.yml

$ cat db/migrate/015_create_foo.rb
class CreateFoo < ActiveRecord::Migration
  def change
    create_table :foo do |t|

      t.timestamps null: false
    end
  end
end

$ cat db/migrate/016_create_bar.rb
class CreateBar < ActiveRecord::Migration
  def change
    create_table :bar do |t|
      t.references :foo, index: true, foreign_key: true

      t.timestamps null: false
    end
  end
end

$ rake db:migrate
...
ActiveRecord::StatementInvalid: Mysql2::Error: Can't create table 'planner_dev.#sql-52f_b' (errno: 150): ALTER TABLE `bar` ADD CONSTRAINT `fk_rails_e70b15738f`
FOREIGN KEY (`foo_id`)
  REFERENCES `foos` (`id`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants