rake 数据库迁移后未初始化的常量
Uninitialized constant after rake db migration
我想使用 rake db:migrate
添加一个名为 measurement_error_categories
的 table。
我用 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
我做错了什么?
好的,我知道了。在 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
所以我将方法名称从 change
更改为 create
。
我想使用 rake db:migrate
添加一个名为 measurement_error_categories
的 table。
我用 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
我做错了什么?
好的,我知道了。在 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
所以我将方法名称从 change
更改为 create
。