You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/bin/sh
rails new sqlite_autoindex
cd sqlite_autoindex
bundle exec rails g scaffold broken
patch db/migrate/* <<EOF
--- 20180709003138_create_brokens.rb 2018-07-08 21:32:20.270221417 -0300
+++ db/migrate/20180709003138_create_brokens.rb 2018-07-08 21:32:39.173220733 -0300
@@ -1,6 +1,6 @@
class CreateBrokens < ActiveRecord::Migration[5.2]
def change
- create_table :brokens do |t|
+ create_table :brokens, id: :string do |t|
t.timestamps
end
EOF
bundle exec rake db:migrate
bundle exec rake test
Expected behavior
Tests passing
Actual behavior
rails aborted!
ArgumentError: Index name 'sqlite_autoindex_brokens_1' on table 'brokens' already exists
Other considerations
The migrations run correctly and yield the following db/schema.rb:
ActiveRecord::Schema.define(version: 2018_07_09_002932) do
create_table "brokens", id: :string, force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["id"], name: "sqlite_autoindex_brokens_1", unique: true
end
end
and running:
RAILS_ENV=test bundle exec rake db:migrate
will get past this error. So teh problem is that this sqlite_autoindex_brokens_1 is automatically created when creating the primary key, but it gets dumped into a separate statement on schema.rb, ending as a duplicate.
I wonder why it doesn't happen with integer keys. Anyway, it shouldn't be dumped to schema.rb.
Related #31201.
If creating custom primary key (like a string) in SQLite, it would also
create an internal index implicitly which named begin with "sqlite_".
It need to be hidden since the internal object names are reserved and
prohibited for public use.
See https://www.sqlite.org/fileformat2.html#intschemaFixes#33320.
ActiveRecord::StatementInvalid:
SQLite3::SQLException: index associated with UNIQUE or PRIMARY KEY constraint cannot be dropped: DROP INDEX "sqlite_autoindex_event_store_events_1"
Related:
rails/rails@7fae8e3rails/rails#33320
Steps to reproduce
Run this:
Expected behavior
Tests passing
Actual behavior
Other considerations
The migrations run correctly and yield the following
db/schema.rb
:and running:
will get past this error. So teh problem is that this
sqlite_autoindex_brokens_1
is automatically created when creating the primary key, but it gets dumped into a separate statement on schema.rb, ending as a duplicate.I wonder why it doesn't happen with integer keys. Anyway, it shouldn't be dumped to schema.rb.
System configuration
<3
The text was updated successfully, but these errors were encountered: