Sqlite3::Sqlexception: Duplicate Column Name While Migrating

SQLite3::SQLException: duplicate column name while migrating

try migrating your DB to version=0
with command: rake db:migrate VERSION=0

and then run
rake db:migrate

Devise rake db:migrate fails because of duplicate column in my User's table - Rails 3.1

Try rake db:rollback and then try again. When you did it the first time it added the id column. and why are you adding id :integer not null, primary key it's automatic in rails. It should look like this:

class CreateProducts < ActiveRecord::Migration
def up
create_table :products do |t|
t.string :email
t.text :f_name

t.timestamps
end
end

def down
drop_table :products
end
end

You can get more information here http://guides.rubyonrails.org/migrations.html

Duplicate Column name in rails

in the second migration take out the line add_column :articles, :description, :text. You already created a description column when you created the articles table in the first migration, with the line t.text :description:

create_table :articles do |t|
t.string :title
t.text :description
t.timestamps null: false
end

That's the duplicate column Rails is referring to in the error. Next time before you run migrations you can check schema.rb file to see what your database tables look like

Missed this the first time, but you also are duplicating your timestamp columns, created_at and updated_at So the second migration is unnecessary

Migrations are cancelled and duplicate column error

SQLite3::SQLException: duplicate column name: activation_digest: ALTER TABLE "users" ADD "activation_digest" varchar

As the exception suggests, you have already added activation_digest in your users table.

You can check the columns of your users table right from the rails console with User.column_names.

AddUserIdToMytimes .. Error - SQLite3::SQLException: duplicate column name: user_id: ALTER TABLE mytimes ADD user_id integer

Seems like your Mytime model already have user_id field.

What could you do? Remove this migration as unnecessary?

Duplicate column name error when running migration

That happens if you migrations are not in sync with the database schema. This could happen if

  • you modified the database schema "by hand"
  • you changed a migration file being run
  • migrations have not been updated in the schema_migrations table

If you are not relying on the data in the database, a rake db:reset would re-run all migrations from scratch. Otherwise you have to make the conflicting migration recognized as already-run by adding to the schema_migrations table.

See RailsGuides of migrations as well.

Rails 4 Migration Error (Can't rake db:migrate) SQLite3::SQLException: duplicate column name

Deleting a migration file doesn't really rollback the change it made in your database. Your best bet is to:

  1. Don't delete the migration but comment out the content of the migration class, and run rake db:migrate,

Let's say I have this as my migration file

class AddEmailSentToNeeds < ActiveRecord::Migration
def change
add_column :needs, :email_sent, :boolean ,default: false
end
end

Just comment out the method but leave the class, so it would be:

class AddEmailSentToNeeds < ActiveRecord::Migration
# def change
# add_column :needs, :email_sent, :boolean ,default: false
# end
end

This is just a hacky way to tell rails to skip this migration.
OR


  1. start from the start so go do, rake db:drop, rake db:create, and rake db:migrate

Rails database migration fails with duplicate column name: email when adding devise's generated User table

So the problem is you already have the users table inside your database. You need to either drop that table and create a new one if it's not working or just continue using that table.

It's not a good idea to drop your database but since you are making a new app(as you creating a users table) so in your case it'll be better to drop that database and recreate it(to make sure everything works). Try these commands in sequence:

rake db:drop
rake db:create
rake db:migrate

It should work fine and you need not do rails generate devise User as you already have your users migration file

Update:

If you don't want to drop your database then you can create a new migration file and delete your users table there.

rails generate migration DropUsersTable

after that edit your migration file

class DropUsersTable < ActiveRecord::Migration
def change
drop_table :users
end
end

and then do rake db:migrate



Related Topics



Leave a reply



Submit