Question

I just reset my database with rake db:reset

I have 3 tables in my models folder: Performer table, Performance table and a relationship table between the two PerformerPerformance.

When i run the db:migrate I get error that the table does not exist

-- 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

Here is my CreatePerformerPerformances migration file:

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

my PerformerPerformance model

class PerformerPerformance < ActiveRecord::Base

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

performer model

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

Performance model:

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

Here is the migration with trace:

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

I know I probably edited some file which is causing the error but i have no idea where to look. If you need additional information or files pls ask and ill post them.

Was it helpful?

Solution

You need to have all the migration functions inside change method

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top