1

在轨道上工作,我注意到轨道迁移的以下行为。我不知道它是否是预期的行为。有人有任何想法吗?轨道的轨道怪异行为破坏迁移

步骤1 - 我已经创建迁移此命令的

rails g migration CreateCustomer

结果 -

invoke active_record 
    create db/migrate/20151012160803_create_customer.rb 

第2步 - 现在我想撤消与上述命令生成的代码。

rails d migration CreateCustomer 

结果这个命令 -

invoke active_record 
    remove db/migrate/20151012160803_create_customer.rb 

第3步 - 如果我运行的第2步命令rails d migration CreateCustomer再次,我得到不同的轨道版本

on Rails的3.2.17结果歧结果是 -

invoke active_record 
    remove migration.rb 

Result on Rails 4.0.0 is -

invoke active_record 
    remove create_table_migration.rb 

我的问题是为什么rails删除migration.rbcreate_table_migration.rb文件?是真的删除这些文件的轨道?

谢谢!

回答

0

不,它并没有真正删除此文件,如果您将运行:

rails d migration SomeUnRealMigration

,你会得到同样的错误,你看那些2文件名是Rails的create_table_migration.rb核心文件:

class <%= migration_class_name %> < ActiveRecord::Migration 
     def change 
     create_table :<%= table_name %> do |t| 
     t.string :email,    null: false 
     t.string :password_digest,  null: false 
     t.string :password_reset_token, null: false, limit: 60 
     <% attributes.each do |attribute| -%> 
      <% if attribute.password_digest? -%> 
      t.string :password_digest<%= attribute.inject_options %> 
      <% else -%> 
      t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %> 
      <% end -%> 
     <% end -%> 
     <% if options[:timestamps] %> 
     t.timestamps 
     <% end -%> 
    end 
    <% attributes_with_index.each do |attribute| -%> 
     add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %> 
    <% end -%> 
    end 
    end 

这不会影响您的应用程序中的任何文件。