Rails 4:SQLException:没有这样的表:

我在Rails4中运行以下代码:

$ bundle exec rake db:migrate

== 201405270646 AddAttachmentImageToPins:迁移=========================== – change_table(:pins)rake aborted! StandardError:发生错误,此以及所有后续迁移都已取消:

SQLite3 :: SQLException:没有这样的表:pins:ALTER TABLE“pins”ADD“image_file_n ame”varchar(255)c:/ Sites / pinteresting / db / migrate / 201405270646_add_attachment_im age_to_pins.rb:4:in block in up' c:/Sites/pinteresting/db/migrate/201405270646_add_attachment_image_to_pins.rb:3: in up’c block in up' c:/Sites/pinteresting/db/migrate/201405270646_add_attachment_image_to_pins.rb:3: in ‘c: block in up' c:/Sites/pinteresting/db/migrate/201405270646_add_attachment_image_to_pins.rb:3: in migrate’任务:TOP => db:migrate(通过使用–trace运行任务来查看完整跟踪)

我无法理解为什么我会收到此错误。

这是我的github: https : //github.com/frankzk/pinteresting

谢谢您的帮助

迁移文件:

 class AddAttachmentImageToPins < ActiveRecord::Migration def self.up change_table :pins do |t| t.attachment :image end end def self.down drop_attached_file :pins, :image end end 

它与迁移的文件名有关。

在运行迁移时,Rails会查看文件名中的时间戳,以确定运行它们的顺序。

如果您查看迁移文件:

 db/migrate/ ├── 20140526033741_devise_create_users.rb ├── 20140526222538_create_pins.rb ├── 20140527032853_add_user_id_to_pins.rb └── 201405270646_add_attachment_image_to_pins.rb 

由于某种原因,您会看到add_attachment_image_to_pins.rb比其他字符短2个字符。 所以它试图首先运行这个,并且在那时,没有创建引脚表导致no such table: pins错误

将其重命名为20140527064600_add_attachment_image_to_pins.rb允许我成功运行迁移。