[RUBY] What to do when an error occurs in rails db: migrate ((StandardError: An error has occurred, this and all later migrations canceled :))

You may get an error with rails db: migrate. In my case, I get some kind of error for some reason, so I tried to find out how to deal with it. (I myself am a beginner in both ruby and rails. I am writing this article for my learning, hoping that it will be helpful for beginners.)

== 20201011010946 CreatePosts: migrating ======================================
-- create_table(:posts)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::DuplicateTable: ERROR:  relation "posts" already exists

(to be continued)

What causes rails db: migrate error?

Regarding this Standard Error, migrate was executed, but an error occurred during execution for some reason, and the table is created but the migrate situation is treated as unexecuted.

In other words, I think it feels like it was interrupted by a small error on the system side.

However, the error statement says /post_bootstrap_app/db/migrate/20201011010946_create_posts.rb:3:in `change'as if there was a mistake there, saying," I'm messing around with that? It becomes a state and is confused for a moment.

What to do when an error (StandardError) occurs in rails db: migrate

rails db:migrate:reset
* Reset the execution of migrate once

rails db:migrate
* Rails db again:Run migrate

I did some research on how to deal with it, but I decided that the interrupted migrate was not reset once, and if I try again with migrate, it will work, so I actually tried this method. It was.

As a result, I succeeded in db: migrate as if nothing had happened!

This summary

I think that some beginners are confused when an error occurs when creating a salty database, saying "Why is an error even though I haven't written much yet?".

However, this simple method may solve the problem, so if you are in trouble, please try it. I hope you find it helpful.

Recommended Posts

What to do when an error occurs in rails db: migrate ((StandardError: An error has occurred, this and all later migrations canceled :))
What to do when an error (StandardError: An error has occurred, this and all later migrations canceled:) appears in rails db: migrate
Error in docker rails db: migrate (StandardError: An error has occurred, all later migrations canceled :)
What to do and how to install when an error occurs in DXRuby 1.4.7
[Rails] Error StandardError: An error has occurred, all later migrations canceled: Column `Foreign key name` on table` Table name` does not match column ʻid` on `Table name`
[Programming beginner] What to do when rails s becomes an error in the local development environment
What to do if an error occurs when doing npm install axios in React + Typescript project
What to do if you get an error during rails db: reset
What to do if an error occurs when nokogiri enters when bundle install
What to do when IllegalStateException occurs in PlayFramework
What to do when rails db: seed does not reflect in the database
What to do if you get an error on heroku rake db: migrate
What to do if ffi installation fails when launching an application in Rails
What to do when a null byte error occurs
What to do if an ActionController :: UnknownFormat error occurs
Error ExecJS :: RuntimeUnavailable: What to do when it occurs
After installing'devise''bootstrap' of gemfile with rails, what to do when url is an error
What to do when you launch an application with rails
About the error that occurred when adding the column name in rails (rails db: migrate, rails db: rollback, add)
Error in rails db: migrate
# What to do if you accidentally do rails db: migrate: drop
What to do if you get an error in Basic authentication during Rails test code
[Rails 6] What to do when a missing a template error occurs after introducing haml [Super easy]
[Rails] What to do if data is not registered in DB
What to do when javax.batch.operations.JobStartException occurs
What to do if an error occurs in VS Code when importing a django module or your own module installed by pip install
Resolved the error that occurred when trying to use Spark in an environment where Java 8 and Java 11 coexist.
What to do if you should have installed Rails but an error occurs with rails -v (for beginners)
Add gem'rails-i18n','~> 6.0.0' and what to do if bundle install gives an error
What to do when Blocked Host: "host name" appears in Ruby on Rails
no space left on device What to do if an error occurs
What to do if you get an error when you hit Heroku logs
Notes on what to do when a WebView ClassNotFoundException occurs in JavaFX 12
What to do when a javax.el.PropertyNotWritableException occurs
What to do if you get an "A server is already running." Error when you try to start the rails server
Solution that gives an error when trying to connect to DB (MySQL) in Java
[Grails] Error occurred running What to do when the Grails CLI does not start
wildflly10 java8 ERROR [org.jboss.jca.core.tx.jbossts.XAResourceRecoveryImpl] (Periodic Recovery) IJ000906 What to do if an error occurs
Summary when trying to use Solr in Java and getting an error (Solr 6.x)
When using a list in Java, java.awt.List comes out and an error occurs
What to do if you get an error saying "Please enter a valid value" when getting with Rails datetime_field
[Rails] What to do when you want to generate an error that cannot be destory when foreign key restrictions are applied
What to do if you get an error saying "Could not find a JavaScript runtime." When starting rails server
[Rails] Solution when migration error occurs in acts-as-taggable-on
After all, what is [rails db: migrate] doing?
[In team development] Error when moving to another member's branch and doing rails s [Rails]
What to do when Address already in use is displayed after executing rails s
[Rails] What to do when rails db: migrate cannot be done because there is no table referenced by the foreign key
<Dot installation> What to do if you cannot proceed due to an error when building a development environment for Rails learning.
What to do if ClassNotFoundException occurs when starting Tomcat
[Rails] "private method` String' called ~ "error when db: migrate
What to do when rails creates a 〇〇 2.rb file
What to do when a could not find driver appears when connecting to a DB in a Docker environment
[Rails Tutorial Chapter 2] What to do when you make a mistake in the column name
What to do if a SAX Parser error occurs when using Liferay 7 / DXP on AWS
[Rails] What to do if you can't get an error message with the errors method
What to do if you get a "302" error in your controller unit test code in Rails
What to do when Rails on Docker does not reflect controller changes in the browser