耙迁移无法找到表

时间:2013-01-30 20:38:56

标签: ruby-on-rails rake rails-migrations

所以我在db-> migrate文件夹中创建了一个手动文件名001_create_users.rb,如下所示:

class CreateUsers < ActiveRecord::Base
  def self.up
    create_table :users do |t|
      t.string :name
      t.string :email
      t.string :password
      t.string :bio

      t.timestamps
    end
  end

  def self.down
    drop_table :users
  end
end

然后我运行:bundle exec rake db:migrate命令,我收到此错误:

  耙子流产了!发生了错误,此错误以及稍后的所有迁移   取消:

     

无法找到表'create_users'

错误更详细,所以我只是从终端窗口复制粘贴,但第一部分是我得到的错误的头部

  耙子流产了!发生了错误,此错误以及稍后的所有迁移   取消:

     

无法找到表'create_users'   /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/connection_adapters/sqlite_adapter.rb:472:in table_structure' /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/connection_adapters/sqlite_adapter.rb:346:in列'   /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/connection_adapters/schema_cache.rb:12:in   block in initialize' /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/model_schema.rb:228:in 收率”   /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/model_schema.rb:228:in   default' /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/model_schema.rb:228:in 列   /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/model_schema.rb:243:in   column_defaults' /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/base.rb:482:in 初始化”   /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/migration.rb:538:in   new' /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/migration.rb:538:in load_migration”   /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/migration.rb:533:in   migration' /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/migration.rb:528:in 迁移”   /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/migration.rb:720:in   block (2 levels) in migrate' /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/migration.rb:775:in 称之为”   /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/migration.rb:775:in   block in ddl_transaction' /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in 交易”   /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/transactions.rb:208:in   transaction' /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/migration.rb:775:in ddl_transaction”   /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/migration.rb:719:in   block in migrate' /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/migration.rb:700:in 每个”   /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/migration.rb:700:in   migrate' /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/migration.rb:570:in 向上”   /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/gems/activerecord-3.2.11/lib/active_record/migration.rb:551:in   'migrate' /Users/JonyIve/Documents/HisFirstService/Rakefile:19:in 阻止(2级)'   /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/bin/ruby_noexec_wrapper:14:in   eval' /Users/JonyIve/.rvm/gems/ruby-1.9.3-p362@railsbabak/bin/ruby_noexec_wrapper:14:in '任务:TOP =&gt; db:migrate(通过运行任务查看完整跟踪   --trace)

此外,如果我说“哪个宝石”就是我得到的:

which gem
/Users/JonyIve/.rvm/rubies/ruby-1.9.3-p362/bin/gem

1 个答案:

答案 0 :(得分:2)

您应该ActiveRecord::Base继承ActiveRecord::Migration

class CreateProjects < ActiveRecord::Migration
  def change
    create_table :projects do |t|
      t.text :title
      t.text :description
      t.text :slug

      t.timestamps
    end
  end
end