Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4: SQLException: no such table:

i am running the following in Rails4:

$ bundle exec rake db:migrate

== 201405270646 AddAttachmentImageToPins: migrating =========================== -- change_table(:pins) rake aborted! StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: no such table: 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: inup' c:in `migrate' Tasks: TOP => db:migrate (See full trace by running task with --trace)

I can't undestand why i am getting this error.

Here is my github: https://github.com/frankzk/pinteresting

Thanks for the help

Migration file:

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
like image 274
frankzk Avatar asked Jun 01 '14 22:06

frankzk


1 Answers

It has to do with the filename of the migration.

When running migrations, Rails looks at the timestamps in the filenames to figure out the order to run them in.

If you look at your migration files:

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

You'll see that add_attachment_image_to_pins.rb is 2 characters shorter than the others for some reason. So it's trying to run this one first and at that point, the pins table hasn't been created leading to the no such table: pins error

Renaming it to 20140527064600_add_attachment_image_to_pins.rb allowed me to run the migrations successfully.

like image 108
allenan Avatar answered Sep 28 '22 14:09

allenan