2014-05-14 37 views
1

我只是重置我的數據庫耙db:reset的SQLException:沒有這樣的表:主要[]:CREATE INDEX

我在我的模型文件夾中3個表:演員表,性能表和兩個PerformerPerformance之間的關係表。

當我運行db:migrate我得到錯誤的表不存在

-- add_index(:performer_performances, :performer_id) 
-- add_index(:performer_performances, :performer_id) 
rake aborted! 
SQLite3::SQLException: no such table: main.performer_performances: CREATE INDEX 
"index_performer_performances_on_performer_id" ON "performer_performances" ("pe 
rformer_id") 
C:/rubyProjects/dads/db/migrate/20140315155732_create_performer_performances.rb: 
9:in `<class:CreatePerformerPerformances>' 
C:/rubyProjects/dads/db/migrate/20140315155732_create_performer_performances.rb: 
1:in `<top (required)>' 
C:131071:in `disable_ddl_transaction' 
Tasks: TOP => db:migrate 
(See full trace by running task with --trace) #ill include output with trace at the end 

這裏是我的CreatePerformerPerformances遷移文件:

class CreatePerformerPerformances < ActiveRecord::Migration 
    def change 
    create_table :performer_performances do |t| 
     t.integer :performer_id 
     t.integer :performance_id 
     t.timestamps 
    end 
    end 
    add_index :performer_performances, :performer_id 
    add_index :performer_performances, :performance_id 
    add_index :performer_performances, [:performer_id, :performance_id], unique: true 
end 

我PerformerPerformance模型

class PerformerPerformance < ActiveRecord::Base 

    belongs_to :performer 
    belongs_to :performance 
    validates :performer_id, presence: true 
    validates :performance_id, presence: true 
end 

表演型號

class Performer < ActiveRecord::Base 
    validates :name, presence: true, length: { maximum: 50 }, uniqueness: { case_sensitive: false } 
    has_many :performer_performances, dependent: :destroy 
    has_many :performances, through: :performer_performances 

    def part_of?(performance) 
    performer_performances.find_by(performance_id: performance.id) 
    end 

    def perform_in!(performance) 
     performer_performances.create!(performance_id: performance.id) 
    end 

end 

性能型號:

class Performance < ActiveRecord::Base 
    validates :date, length: { maximum: 30 } 
    validates :location, length: { maximum: 60 } 
    has_many :performer_performances, dependent: :destroy 
    has_many :performers, through: :performer_performances 

    def has_performer?(performer) 
    performer_performances.find_by(performer_id: performer.id) 
    end 

    def include! (performer) 
    performer_performances.create!(performer_id: performer.id) 
    end 

end 

這裏是與跟蹤遷移:我知道我可能編輯了一些文件,導致錯誤

DL is deprecated, please use Fiddle 
** Invoke db:migrate (first_time) 
** Invoke environment (first_time) 
** Execute environment 
** Invoke db:load_config (first_time) 
** Execute db:load_config 
** Execute db:migrate 
-- add_index(:performer_performances, :performer_id) 
-- add_index(:performer_performances, :performer_id) 
rake aborted! 
SQLite3::SQLException: no such table: main.performer_performances: CREATE INDEX 
"index_performer_performances_on_performer_id" ON "performer_performances" ("pe 
rformer_id") 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.8-x86-mingw32/lib/sqlite3/databa 
se.rb:91:in `initialize' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.8-x86-mingw32/lib/sqlite3/databa 
se.rb:91:in `new' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.8-x86-mingw32/lib/sqlite3/databa 
se.rb:91:in `prepare' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.8-x86-mingw32/lib/sqlite3/databa 
se.rb:134:in `execute' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/connect 
ion_adapters/sqlite3_adapter.rb:331:in `block in execute' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/connect 
ion_adapters/abstract_adapter.rb:435:in `block in log' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.3/lib/active_support/notif 
ications/instrumenter.rb:20:in `instrument' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/connect 
ion_adapters/abstract_adapter.rb:430:in `log' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/connect 
ion_adapters/sqlite3_adapter.rb:331:in `execute' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/connect 
ion_adapters/abstract/schema_statements.rb:522:in `add_index' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/migrati 
on.rb:625:in `block in method_missing' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/migrati 
on.rb:597:in `block in say_with_time' 
C:/Ruby200/lib/ruby/2.0.0/benchmark.rb:281:in `measure' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/migrati 
on.rb:597:in `say_with_time' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/migrati 
on.rb:617:in `method_missing' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/migrati 
on.rb:383:in `method_missing' 
C:/rubyProjects/dads/db/migrate/20140315155732_create_performer_performances.rb: 
9:in `<class:CreatePerformerPerformances>' 
C:/rubyProjects/dads/db/migrate/20140315155732_create_performer_performances.rb: 
1:in `<top (required)>' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.3/lib/active_support/depen 
dencies.rb:229:in `require' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.3/lib/active_support/depen 
dencies.rb:229:in `block in require' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.3/lib/active_support/depen 
dencies.rb:214:in `load_dependency' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.3/lib/active_support/depen 
dencies.rb:229:in `require' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/migrati 
on.rb:718:in `load_migration' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/migrati 
on.rb:714:in `migration' 
C:131071:in `disable_ddl_transaction' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/migrati 
on.rb:1012:in `use_transaction?' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/migrati 
on.rb:922:in `rescue in block in migrate' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/migrati 
on.rb:919:in `block in migrate' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/migrati 
on.rb:916:in `each' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/migrati 
on.rb:916:in `migrate' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/migrati 
on.rb:764:in `up' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/migrati 
on.rb:742:in `migrate' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/railtie 
s/databases.rake:42:in `block (2 levels) in <top (required)>' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `call' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `block i 
n execute' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `each' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `execute 
' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:175:in `block i 
n invoke_with_call_chain' 
C:/Ruby200/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:168:in `invoke_ 
with_call_chain' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:161:in `invoke' 

C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:149:in ` 
invoke_task' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in ` 
block (2 levels) in top_level' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in ` 
each' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in ` 
block in top_level' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:115:in ` 
run_with_threads' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:100:in ` 
top_level' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:78:in `b 
lock in run' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:165:in ` 
standard_exception_handling' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:75:in `r 
un' 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.1/bin/rake:33:in `<top (required)> 
' 
C:/Ruby200/bin/rake:23:in `load' 
C:/Ruby200/bin/rake:23:in `<main>' 
Tasks: TOP => db:migrate 

,但我不知道去哪裏找。如果您需要額外的信息或文件,請提問併發送錯誤信息。

回答

4

你需要有內部change方法全部遷移功能

class CreatePerformerPerformances < ActiveRecord::Migration 

    def change 

    create_table :performer_performances do |t| 
     t.integer :performer_id 
     t.integer :performance_id 
     t.timestamps 
    end 

    add_index :performer_performances, :performer_id 
    add_index :performer_performances, :performance_id 
    add_index :performer_performances, [:performer_id, :performance_id], unique: true 
    end 
end 
+0

謝謝你這麼多notepadd ++有,如果你持有SHIFT + CTRL搬東西,然後按向上的箭頭,我必須這樣做,是一個選項。現在我只有一個問題,我的索引名稱太長,但我認爲生病可以修復該問題 – Xitcod13

+0

很高興您將它分類。考慮RubyMine。這是值得的。 –

相關問題