我在Rails4中运行以下代码:
$ bundle exec rake db:migrate
= = 201405270646 AddAttachmentImageToPins:迁移 ===========================——change_table(:pins) rake abort !StandardError:发生了一个错误,这次和以后所有的迁移都被取消了:
SQLite3::SQLException: no such table: pins: ALTER table "pins" ADD"image_file_n ame"varchar (255) c:/网站/pinterest/db/migrate/201405270646 _add_attachment_image_to_pins。rb:4:in
运行任务block in up' c:/Sites/pinteresting/db/migrate/201405270646_add_attachment_image_to_pins.rb:3: in
up' c:in ' migrate' Tasks: TOP => db:migrate(参见完整跟踪)使用——trace)
我不明白为什么我得到这个错误。
这是我的github: https://github.com/frankzk/pinterestingThanks for the help
迁移文件: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
允许我成功运行迁移。