0

내 클라이언트 테이블에 전자 메일이라는 열이 있습니다. 그러나 클라이언트 컨트롤러와 모델에 대한 테스트를 수행 할 때 클라이언트 테이블에 전자 메일이라는 열이 없다는 테스트가 계속있었습니다. Ruby on rails, 테스트에 열이 존재하지 않지만 스키마의

sqlite3를 ::되는 SQLException

: 내가 처음에 때 열을 넣지 않았다는 것을 인정 않지만 "클라이언트"("이메일")

를 ON UNIQUE INDEX "index_clients_on_email을"CREATE : 테이블 클라이언트는 더 열 이름 이메일이 없습니다 내 테이블을 만들었지 만 별도의 마이그레이션을 통해이 열을 추가했습니다. 나는 rake db : migrate를 실행했고 심지어 rake db : drop을 시도했다. drop : all, rake db : create : all 그리고 rake db : migrate 그리고 그것은 여전히 ​​아무것도 변경하지 않았다.

이메일 열이 클라이언트 테이블의 색인으로 추가되었습니다.

내 스키마입니다 :

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 

클라이언트 테이블에 대한 초기 마이그레이션 :

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

:

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 

마이그레이션 클라이언트 테이블에 대한 인덱스로 이메일을 추가 할 수 이전 : 이메일 열 추가 :

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

다음 내 database.yml을 수 있습니다 :

# SQLite version 3.x 
# gem install sqlite3 
# 
# Ensure the SQLite 3 gem is defined in your Gemfile 
# gem 'sqlite3' 
# 
default: &default 
    adapter: sqlite3 
    pool: 5 
    timeout: 5000 

development: 
    <<: *default 
    database: db/development.sqlite3 

# Warning: The database defined as "test" will be erased and 
# re-generated from your development database when you run "rake". 
# Do not set this db to the same as development or production. 
test: 
    <<: *default 
    database: db/test.sqlite3 

production: 
    <<: *default 
    database: db/production.sqlite3 
+0

당신이 DEV 및 테스트 환경에 동일한 데이터베이스를 사용하십니까? 'RAILS_ENV = test rake db : migrate'를 시도해보십시오. database.yml을 보여주세요. – Thanh

+0

두 가지 환경을 의식적으로 전환하는 것을 기억하지 못합니다. database.yml은 어디에서 찾을 수 있습니까? – Tito

+0

결코 마음을 알지 못했습니다. 방금 찾았습니다. – Tito

답변

0

시도 :

RAILS_ENV=test bundle exec rake db:schema:load 
+0

방금 ​​시도해 보았는데 이후에 rake db : migrate를 시도해 보았습니다. 그러면 동일한 오류가 발생했습니다. – Tito

+0

무엇이 오류입니까? 여기에 그것을 인쇄하십시오. – Hummusawy