数据库迁移错误

时间:2013-07-22 00:49:20

标签: ruby-on-rails linux migrate

当我尝试执行以下操作时出现以下错误:rake db:migrate

rake db:migrate
-- selt()
-- selt()
rake aborted!
ActiveRecord::MigrationProxy#disable_ddl_transaction delegated to migration.disable_ddl_transaction, but migration is nil: #<struct ActiveRecord::MigrationProxy name="DoNothingYet", version=20130722001522, filename="/Users/tidydee/Sites/simple_cms/db/migrate/20130722001522_do_nothing_yet.rb", scope="">
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:712:in `rescue in disable_ddl_transaction'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:708:in `disable_ddl_transaction'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:1012:in `use_transaction?'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:922:in `rescue in block in migrate'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:919:in `block in migrate'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:916:in `each'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:916:in `migrate'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:764:in `up'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:742:in `migrate'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

这是我的DoNothingYet迁移文件:

class DoNothingYet < ActiveRecord::Migration
  def change
  end

  def self.up 
    # instructions for changing the db to a new state
  end

  def selt.down
    #intructiosn for changing the db back to the previous state
  end
end

语法错误:

rake db:migrate
rake aborted!
/Users/tidydee/Sites/simple_cms/db/migrate/20130722001921_create_users.rb:4: syntax error, unexpected ':', expecting keyword_end
    t.string "first_name" :limit => 25
                           ^
/Users/tidydee/Sites/simple_cms/db/migrate/20130722001921_create_users.rb:5: syntax error, unexpected ':', expecting keyword_end
    t.string "last_name" :limit => 50
                          ^
/Users/tidydee/Sites/simple_cms/db/migrate/20130722001921_create_users.rb:6: syntax error, unexpected ':', expecting keyword_end
    t.string "email" :default => "", :null => false
                      ^
/Users/tidydee/Sites/simple_cms/db/migrate/20130722001921_create_users.rb:7: syntax error, unexpected ':', expecting keyword_end
    t.string "password" :limit => 40
                         ^
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:718:in `load_migration'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:714:in `migration'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:708:in `disable_ddl_transaction'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:1012:in `use_transaction?'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:1004:in `ddl_transaction'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:958:in `execute_migration_in_transaction'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:920:in `block in migrate'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:916:in `each'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:916:in `migrate'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:764:in `up'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:742:in `migrate'
/Users/tidydee/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'

用户的迁移文件:

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
    t.string "first_name" :limit => 25
    t.string "last_name" :limit => 50
    t.string "email" :default => "", :null => false
    t.string "password" :limit => 40
    t.timestamps

    end
  end

def self.down
   drop_table:us   
end

end

有谁知道为什么?我怎样才能正确迁移

1 个答案:

答案 0 :(得分:1)

您在此部分中有错误

def selt.down
end

应该是:

def self.down
end

另外,在迁移中你应该放

t.string "first_name", :limit => 25

而不是

t.string "first_name" :limit => 25