运行`rake db:migrate`时,为什么Rails会忽略迁移文件?

时间:2017-02-09 11:33:59

标签: ruby-on-rails ruby

我有一些迁移文件,由于某些原因,db:migrate任务只是忽略了一个迁移文件。

class Assets < ActiveRecord::Migration
  def change
    create_table :assets do |t|
      t.string :title
      t.string :file
      t.string :description

      t.timestamps null: false
    end
  end


end

我已经尝试更改此迁移的顺序,以确保它在需要其创建的表的任何其他迁移之前运行。

1 个答案:

答案 0 :(得分:0)

以下是rake命令列表:

rake db:create          # Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)
rake db:drop            # Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases)
rake db:fixtures:load   # Load fixtures into the current environment's database
rake db:migrate         # Migrate the database (options: VERSION=x, VERBOSE=false)
rake db:migrate:status  # Display status of migrations
rake db:rollback        # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rake db:schema:dump     # Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load     # Load a schema.rb file into the database
rake db:seed            # Load the seed data from db/seeds.rb
rake db:setup           # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)
rake db:structure:dump  # Dump the database structure to db/structure.sql
rake db:version         # Retrieves the current schema version number

尝试bundle exec rake db:drop:all会删除所有migrations等,然后再次尝试创建表格。