0

所以我在 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_adapter/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:incolumns' /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 yield' /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 columns' /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 migrate'/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 call' /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 transaction' /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:在 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 up'/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 block (2 levels) in ' /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 'Tasks: TOP => db:migrate(通过使用 --trace 运行任务查看完整跟踪)

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

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

1 回答 1

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
于 2013-01-30T20:43:50.543 回答