是“ Person”是备用词吗?

som*_*ing 1 ruby ruby-on-rails ruby-on-rails-5

我正在创建一个名为“ Person”的新模型,但它会在数据库中返回创建的“ people”表,我已尝试多次生成和销毁该表,甚至更改了迁移文件以创建表名“ persons”而不是“ people”,包括文件名,但是当我尝试创建或获取数据时,它说:

Mysql2::Error: Table 'database-name_development.people' doesn't exist: SHOW FULL FIELDS FROM `people`
Run Code Online (Sandbox Code Playgroud)

这是生成的示例:

rails g model Person
Running via Spring preloader in process 17268
      invoke  active_record
      create    db/migrate/20190517080311_create_people.rb
      create    app/models/person.rb
      invoke    rspec
      create      spec/models/person_spec.rb
Run Code Online (Sandbox Code Playgroud)

文件:20190517080311_create_people.rb

class CreatePeople < ActiveRecord::Migration[5.1]
  def change
    create_table :people do |t|
      t.timestamps
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

mah*_*off 5

这是由于Rails的变形框架造成的。它具有人与人之间的内置映射。

您应该能够使用以下内容覆盖它,您可以将其放入config/initializers/inflections.rb(或该文件夹中的任何其他名称):

ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.irregular 'person', 'persons'
end
Run Code Online (Sandbox Code Playgroud)