How to decide that "index unique_schema_migrations already exists" in Rails?

Running rake db:migrate , followed by rake test:units , gives the following:

 rake test:functionals (in /projects/my_project) rake aborted! SQLite3::SQLException: index unique_schema_migrations already exists: CREATE UNIQUE INDEX "unique_schema_migrations" ON "ts_schema_migrations" ("version") 

The relevant part of db/schema.rb as follows:

 create_table "ts_schema_migrations", :id => false, :force => true do |t| t.string "version", :null => false end add_index "ts_schema_migrations", ["version"], :name => "unique_schema_migrations", :unique => true 

I do not manually change this index anywhere, and I use the default SQLite3 Rails adapter with a new database. (That is, running rm db/*sqlite3 before rake db:migrate does not help.)

Can the test:units task try to reload the circuit? If so, why? Shouldn't he recognize a circuit already updated?

+4
source share
3 answers

In SQLite, the uniqueness of the index name is applied at the database level. In MySQL, uniqueness applies only at the table level. This is why your migrations work in the last, not the first: you have two indexes with the same name in different tables.

Rename the index or find and rename another unique_schema_migrations index, and your migrations should work.

+14
source

Does your database.yml file have your environments configured to connect to various development and testing databases?

IE:

 development: adapter: sqlite3 database: db/dev.sqlite3 timeout: 5000 test: adapter: sqlite3 database: db/test.sqlite3 timeout: 5000 
+2
source

Try searching if your schema.rb file does not contain other declarations that create an index with the same name: unique_schema_migrations

0
source

Source: https://habr.com/ru/post/1277737/


All Articles