Home>
When I tried redeploying on Heroku,
I got an error. ..
to no file migration file
touch db/migrate/20200811115754_hoga.rb
I tried to replace the file with the command, but it didn't work...
Status Migration ID Migration Name
--------------------------------------------------
(2.6ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
up 20200805054129 Devise create users
up 20200805061051 Create sns credentials
up 20200808070314 Create books
up 20200808070822 Create active storage tablesactive storage
up 20200810072111 ********** NO FILE **********
up 20200811115754 ********** NO FILE **********
up 20200811131113 ********** NO FILE **********
down 20210810072111 Create messages
down 20210810072112 Create favorites
heroku run rails db:rollback
ActiveRecord::UnknownMigrationVersionError:
heroku run rails db:migrate
Index name'index_messages_on_book_id' on table'messages' already exists
heroku run rails db:migrate:reset was also useless. ..
ActiveRecord::ProtectedEnvironmentError: You are attempting to run a destructive action against your'production' database.
If i am sure I want to continue, run the same command with the environment variable:
DISABLE_DATABASE_ENVIRONMENT_CHECK=1
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3.2/lib/active_record/tasks/database_tasks.rb:63:in `check_protected_environments!'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3.2/lib/active_record/railties/databases.rake:15:in `block (2 levels) in<main>'
/app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'/app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/command.rb:48:in `invoke'
/app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/commands.rb:18:in `<main>'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `block in require'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:291:in `load_dependency'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `require'
/app/bin/rails:9:in `<main>'
Tasks: TOP =>db:migrate:reset =>db:drop =>db:check_protected_environments
(See full trace by running task with --trace)
schema.rb
create_table "favorites", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.integer "user_id"
t.integer "book_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["user_id", "book_id"],
name: "index_favorites_on_user_id_and_book_id", unique: true
end
create_table "messages", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.text "text"
t.bigint "book_id"
t.bigint "user_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: falseend
rollback
heroku run rails db:rollback
Running rails db:rollback on ⬢ books-28291... up, run.1599 (Free)
DEPRECATION WARNING: Including LoggerSilence is deprecated and will be removed in Rails 6.1. Please use `ActiveSupport::LoggerSilence` instead (called from<main>at /app/config/application.rb:7)
(2.1ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode,',STRICT_ALL_TABLES'),',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
(3.7ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
(2.0ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
(2.0ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
rails aborted!
ActiveRecord::UnknownMigrationVersionError:
No migration with version number 20200811131113.
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3.2/lib/active_record/migration.rb:1169:in `move'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3.2/lib/active_record/migration.rb:1047:in `rollback'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3.2/lib/active_record/railties/databases.rake:225:in `block (2 levels) in<main>'
/app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/command.rb:48:in `invoke'
/app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/commands.rb:18:in `<main>'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `block in require'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:291:in `load_dependency'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `require'
/app/bin/rails:9:in `<main>'
Tasks: TOP =>db:rollback
-
Answer # 1
-
Answer # 2
heroku run rails db:migrate:reset DISABLE_DATABASE_ENVIRONMENT_CHECK=1
Is useful when using heroku
Related articles
- ruby - rails app can't deploy to heroku
- ruby - heroku run rails db: cannot migrate
- ruby - rails cannot be started in the production environment when building an ec2 environment
- ruby on rails - cannot save nested child model
- ruby on rails - heroku: how to check the database_url used for regular backup
- ruby on rails 5 - the time notation cannot be written normally
- ruby on rails - i cannot save a comment on the comment posting page
- python - cannot deploy to heroku environment error
- ruby on rails - data cannot be saved in the intermediate table (parameters cannot be passed)
- ruby on rails - you cannot change the keychain after downloading the pem file when creating an ec2 instance the matter that come
- ruby on rails - cannot pass id to destroy action of intermediate table
- ruby on rails - i want to deploy to aws ec2 server
- ruby on rails - i want to start the puma server and deploy the rails app
- [rails 6] rails db: migrate cannot be done on heroku
- ruby on rails - syntax error cannot be resolved
- ruby on rails - when i access the rails 6 site on heroku with my own domain, it says "this connection does not protect priv
- ruby on rails 5 - rails cannot retrieve params data
- ruby on rails - image cannot be saved (activestorage installed) null in image of table
- ruby on rails - cannot start unicorn cannot load `railsconfigactive_storageservice`
- ruby - [rails] i want to deploy a rails application using elastic beanstalk
Related questions
- ruby on rails - pg :: datatypemismatch error when doing heroku run rails db: migrate
- javascript - jquery doesn't work on heroku
- ruby - about accelerating heroku's rails app
- ruby - rails app can't deploy to heroku
- mysql - can't db: migrate to heroku
- ruby on rails - "this connection does not protect your privacy"
- ruby - can't db: migrate after deploying to heroku
- information entered in db is not registered ruby on rails
- [heroku] about the problem that status = 500 is returned only when using a smartphone when logging in to twitter using omniauth
- in ruby on rails, i want to limit it to information other than foreign key constraint in references
I will describe it because the answer was derived from the question.
Organize the problemIt seems that an index named index_messages_on_book_id has already been pasted in the messages table.
Is _book_id written multiple times in the file under db/migrate/?
It was recognized that the file has not been migrated yet because the file name was rewritten, and tried to create the message table again.
There is a possibility.
SolutionPlease restore the file name and all contents of the file once.
To