Spec-Zone.ru › Ruby on Rails 5.1

класс ActiveRecord::MismatchedForeignKey

Родитель:
ActiveRecord::StatementInvalid

Выбрасывается, когда ограничение внешнего ключа не может быть добавлено, потому что тип столбца не соответствует типу связанного столбца.

Публичные методы класса

new(adapter = nil, message: nil, table: nil, foreign_key: nil, target_table: nil, primary_key: nil) Показать исходный код
# File activerecord/lib/active_record/errors.rb, line 118
    def initialize(adapter = nil, message: nil, table: nil, foreign_key: nil, target_table: nil, primary_key: nil)
      @adapter = adapter
      if table
        msg = "          Column `#{foreign_key}` on table `#{table}` has a type of `#{column_type(table, foreign_key)}`.
          This does not match column `#{primary_key}` on `#{target_table}`, which has type `#{column_type(target_table, primary_key)}`.
          To resolve this issue, change the type of the `#{foreign_key}` column on `#{table}` to be :integer. (For example `t.integer #{foreign_key}`).
".strip_heredoc
      else
        msg = <<-EOM
          There is a mismatch between the foreign key and primary key column types.
          Verify that the foreign key column type and the primary key of the associated table match types.
        EOM
      end
      if message
        msg << "\nOriginal message: #{message}"
      end
      super(msg)
    end
Вызывает метод родительского класса ActiveRecord::StatementInvalid.new

© 2004–2018 David Heinemeier Hansson
Licensed under the MIT License.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API