Why do I keep getting an error that there's a duplicate field in my Table when it's not true?

StackOverflow https://stackoverflow.com/questions/23209320

سؤال

I am attempting to use Paperclip in my Ruby on Rails project but I keep getting this error in my Terminal:

SQLite3::SQLException: duplicate column name: image_file_name: ALTER TABLE "orders" ADD "image_file_name"

I get this right after I type in rake db:migrate with a migration file that looks like this:

class AddAttachmentImageToOrders < ActiveRecord::Migration

  def self.up
    change_table :orders do |t|
      t.attachment :image
    end
  end

  def self.down
    drop_attached_file :orders, :image
  end

end

However, my schema file looks like this:

create_table "orders", force: true do |t| t.integer "transaction_id" t.datetime "created_at" t.boolean "shipped" t.datetime "updated_at" t.text "name" t.text "email_address" t.text "address_1" t.text "address_2" t.text "city" t.text "state" t.integer "zip" t.string "size" end

I'm sure there's something I'm missing. If it's not seeing the duplicate in the schema, where is it seeing it?

هل كانت مفيدة؟

المحلول

Your problem is your database already has those columns

Paperclip uses t.attachment to input these columns to your db:

[attachment]_file_name
[attachment]_content_type
[attachment]_file_size
[attachment]_updated_at

Your t.attachment basically means you're trying to create one of these columns, but they already exist. The way to fix this is to just get rid of the contents of that migration, run rake db:migrate again, then delete the file

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top