неопределенный метод `to_sym 'для nil: NilClass RoR - PullRequest
0 голосов
/ 24 сентября 2018

Это моя первая публикация о переполнении стека, надеюсь, вы мне поможете.Я работаю с RoR и PostgreSQL, gem 'devise.


В консоли rails я пытаюсь удалить данные из таблицы "Конкурент", но у меня появляется следующая ошибка, и я не былспособен решить эту проблему.

2.4.1: 006> c.destroy (c) ActiveRecord :: UnknownPrimaryKey: неизвестный первичный ключ для таблицы конкурентов в модели Competitor.

This is my competitors table, which it's was generate with model of gem devise

create_table "competitors", id: false, force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.bigint "rut"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
t.string "lastname"
t.integer "phone"
t.date "dateOfBirth"
t.boolean "gender"
t.string "numberSerie"
t.string "otp_secret_key"
t.integer "otp_module", default: 0
t.index ["email"], name: "index_competitors_on_email", unique: true
t.index ["reset_password_token"], name: "index_competitors_on_reset_password_token", unique: true
t.index ["rut"], name: "index_competitors_on_rut", unique: true

endere

и это модель

class Competitor < ApplicationRecord


# Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  has_many :raffle_registers, primary_key: 'rut', foreign_key: 'rutCompetitors'
  has_many :accountpays
  has_one :found

  #otp model to make it use TFA
  has_one_time_password

  enum otp_module: { disabled: 0, enabled: 1 }, _prefix: true
  attr_accessor :otp_code_token


end

1 Ответ

0 голосов
/ 24 сентября 2018

Вы создали таблицу участников без первичного ключа.Оформить заказ:

create_table "competitors", id: false, force: :cascade do |t|

id: false это ваша проблема.Проверьте миграцию, чтобы создать таблицу competitors и задать первичный ключ (или создать новую миграцию, добавив к ней первичный ключ).

Полезный ресурс: https://stackoverflow.com/a/10079409/740394

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...