Error duplicating column name when starting migration

Whenever I start a migration in my Rails application, I get a SQLite3 error message:

SQLite3::SQLException: duplicate column name: photo_file_name: ALTER TABLE "users" ADD "photo_file_name" varchar(255) 

I already have the "Add photo to user" migration. There he is:

 class AddAttachmentPhotoToUsers < ActiveRecord::Migration def self.up change_table :users do |t| t.has_attached_file :photo end end def self.down drop_attached_file :users, :photo end end 

And here is the user migration:

 class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :name t.string :title t.string :department t.text :skills t.boolean :available t.timestamps end end end 

I'm a little confused by this because it tells me that there is a duplicate column name "photo_file_name", but do I need to add it to the "Users" table? It does not make sense. Don't I need to delete it?

Let me know if you need any other details about my application.

+6
source share
2 answers

This happens if you are not in sync with the database schema. This can happen if

  • you changed the database schema manually
  • you changed the migration file that is running
  • migrations were not updated in the schema_migrations table

If you are not relying on the data in the database, rake db:reset will restart all migrations from scratch. Otherwise, you must make the conflicting migration already recognized by adding schema_migrations to the table.

See RailsGuides for migrations .

+15
source

I also solved this problem by going into the heroku database and then dropping only the offending column. I think this is a less destructive solution.

0
source

All Articles