I had a similar problem, and I suggest following this path. Migrate in two steps: for example, suppose you have a migration called users. Transfer it as usual, but here is not yet unique.
class CreateUsers < ActiveRecord::Migration def change create table :users do |t| t.integer :name t.integer :email t.timestamps end end end
Migration with:
$ bundle exec rake db:migrate
After the migration, create another migration:
$ rails generate migration add_index_users_name_email
In this migration file, add uniqueness:
class AddIndexUsersNameEmail < ActiveRecord::Migration def change add_index :users, :name, unique: true add_index :users, :email, unique: true end end
Reschedule as usual, and this should work and will not generate errors, because, as Ivan said, SQLite provides uniqueness at the db level, and thus solves the problem.
Another way to solve this problem, if you still throw errors, is to create a separate migration for each record. For instance:
$ rails generate migration add_index_users_name $ rails generate migration add_index_users_email class AddIndexUsersName < ActiveRecord::Migration def change add_index :users, :name, unique: true end end class AddIndexUsersEmail < ActiveRecord::Migration def change add_index :users, :email, unique: true end end
Let me know if your problem solves