2017-06-20 59 views
0

我想添加一個名爲measurement_error_categories的表,使用rake db:migrate耙子數據庫遷移後未初始化的常量

我創建了一個遷移文件,bundle exec rake db:create_migration NAME=create_measurement_error_category_table 現在我得到以下錯誤運行bundle exec rake db:migrate

== 20170620084816 CreateMeasurementErrorCategoryTable: migrating ============== 
rake aborted! 
An error has occurred, this and all later migrations canceled: 

uninitialized constant CreateMeasurementErrorCategoryTable::MeasurementErrorCategory 
/Users/ndinatale/leanlogic-qa-prototype/server/db/migrate/20170620084816_create_measurement_error_category_table.rb:3:in `change' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/migration.rb:602:in `exec_migration' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/migration.rb:586:in `block (2 levels) in migrate' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/migration.rb:585:in `block in migrate' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/migration.rb:584:in `migrate' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/migration.rb:759:in `migrate' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/migration.rb:998:in `block in execute_migration_in_transaction' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/migration.rb:1044:in `block in ddl_transaction' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `block in transaction' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/connection_adapters/abstract/database_statements.rb:209:in `within_new_transaction' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `transaction' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/transactions.rb:208:in `transaction' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/migration.rb:1044:in `ddl_transaction' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/migration.rb:997:in `execute_migration_in_transaction' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/migration.rb:959:in `block in migrate' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/migration.rb:955:in `each' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/migration.rb:955:in `migrate' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/migration.rb:814:in `up' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/migration.rb:792:in `migrate' 
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>' 
/Library/Ruby/Gems/2.0.0/gems/bundler-1.14.3/lib/bundler/cli/exec.rb:74:in `load' 
/Library/Ruby/Gems/2.0.0/gems/bundler-1.14.3/lib/bundler/cli/exec.rb:74:in `kernel_load' 
/Library/Ruby/Gems/2.0.0/gems/bundler-1.14.3/lib/bundler/cli/exec.rb:27:in `run' 
/Library/Ruby/Gems/2.0.0/gems/bundler-1.14.3/lib/bundler/cli.rb:335:in `exec' 
/Library/Ruby/Gems/2.0.0/gems/bundler-1.14.3/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run' 
/Library/Ruby/Gems/2.0.0/gems/bundler-1.14.3/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command' 
/Library/Ruby/Gems/2.0.0/gems/bundler-1.14.3/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch' 
/Library/Ruby/Gems/2.0.0/gems/bundler-1.14.3/lib/bundler/cli.rb:20:in `dispatch' 
/Library/Ruby/Gems/2.0.0/gems/bundler-1.14.3/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start' 
/Library/Ruby/Gems/2.0.0/gems/bundler-1.14.3/lib/bundler/cli.rb:11:in `start' 
/Library/Ruby/Gems/2.0.0/gems/bundler-1.14.3/exe/bundle:32:in `block in <top (required)>' 
/Library/Ruby/Gems/2.0.0/gems/bundler-1.14.3/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors' 
/Library/Ruby/Gems/2.0.0/gems/bundler-1.14.3/exe/bundle:24:in `<top (required)>' 
/usr/local/bin/bundle:23:in `load' 
/usr/local/bin/bundle:23:in `<main>' 
Tasks: TOP => db:migrate 
(See full trace by running task with --trace) 

20170620084816_create_measurement_error_category_table.rb後:

class CreateMeasurementErrorCategoryTable < ActiveRecord::Migration 
    def change 
    MeasurementErrorCategory.create_table(self, :measurementerrorcategories) 
    end 
end 

measurement_error_category.rb:

class MeasurementErrorCategory < ActiveRecord::Base 
    include ModelBase 
    include Ordering 

    # ----- 
    # Table setup 
    # ----- 
    before_validation { complete_languageblock(false, :name) } 

    validates :name, language: { complete: :all, minlength: 3 } 

    # serialize json object (value) as newline delimited string in the database 
    serialize :name 

    augment_class_usertag 

    def self.create_table(m,tn) 
    m.create_table tn do |t| 
     t.string :name 
     t.integer :seqnum 
     augment_table_usertag t 
    end 
    end 
end 

有什麼我完成了錯誤?

+0

嘗試'MeasurementErrorCategory.create_table(self,:measurement_error_categories)' –

+0

@ Md.FarhanMemon不幸的是,同樣的錯誤。 – RagnarLothbrok

回答

1

好吧,我發現了。在20170620084816_create_measurement_error_category_table.rb我改變

class CreateMeasurementErrorCategoryTable < ActiveRecord::Migration 
    def change 
    MeasurementErrorCategory.create_table(self, :measurementerrorcategories) 
    end 
end 

class CreateMeasurementErrorCategoryTable < ActiveRecord::Migration 
    def create 
    MeasurementErrorCategory.create_table(self, :measurementerrorcategories) 
    end 
end 

所以我改變了方法名從changecreate

相關問題