samedi 31 décembre 2016

Ruby on rails , test is saying a column doesn't exist but its on the schema

in my clients table, I have a column named email. But when I made the tests for the clients controller and the model, the tests kept on saying that the clients table has no column named email.

although I do admit that I didn't initially put that column when I created my table, but I added the column via a separate migration. I ran rake db:migrate and even tried rake db:drop:all, rake db:create:all and then rake db:migrate and it still didn't change anything.

the email column was also added as an index for the clients table.

this is my schema:

ActiveRecord::Schema.define(version: 20161230163248) do

  create_table "clients", force: :cascade do |t|
    t.string   "name",       null: false
    t.text     "email",      null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  add_index "clients", ["email"], name: "index_clients_on_email", unique: true

  create_table "projects", force: :cascade do |t|
    t.text     "project_description", null: false
    t.string   "project_timescale"
    t.datetime "created_at",          null: false
    t.datetime "updated_at",          null: false
    t.integer  "client_id"
  end

  add_index "projects", ["client_id"], name: "index_projects_on_client_id"

end

the initial migration for the clients table:

class CreateClients < ActiveRecord::Migration
  def change
    create_table :clients do |t|
      t.string :name, presence: true, null: false
      t.timestamps null: false
    end
  end
end

migration to add email as an index for the client table:

class AddIndexToClient < ActiveRecord::Migration
  def change
    add_index:clients, :email, unique: true
  end
end

migration to add the email column:

class AddEmailToClient < ActiveRecord::Migration
  def change
    add_column :clients, :email, :text
  end
end

Aucun commentaire:

Enregistrer un commentaire