[RUBY] The idea of cutting off when the error is not resolved

Hi, this is Teppei Mimachi.

When I'm programming, I always encounter an error. Some errors are easy to resolve, while others are unmotivated and can't be resolved in hours or even days.

Here's one technique that you might be able to use for errors that can help you when you're discouraged. This time, the error occurred in Ruby on Rails, but if it is a database-related error, it is effective in any programming language development environment regardless of Rails.

This time, it took 3 days from the occurrence of the error to solve it, so I tried to summarize it in a short and easy-to-understand manner.

First, the conclusion

To outline this article __ If the database looks like the original, it's faster to recreate the database. __ The story.

Then, have a three-day fight!

Day 1. Template :: Error

スクリーンショット 2020-09-09 13.33.02.png

undefined method `image_name' for nil:NilClass

When I picked up the above sentence and ignored the for nil: NilClass part It means __image_name method is not defined __.

__1. Forgot to define a method 2. Simple typographical errors __

I doubted this area and tried various things, Method definition Neither bad nor typographical errors ...

Even if I try to google, I can not reach the correct answer ...

For the time being, I was tired and fell asleep on the first day.

Day 2. Database-like

I re-examined for typographical errors, but there was no problem.

I didn't pay much attention here

for nil:NilClass

I will try to google about the part of.

By the way, if you have never used Ruby, What is nil? May be, but

__nil is synonymous with null. __ In other words, __ "nothing" __.

One thing that comes to mind is that there is nothing ... __ It seems to be related to the database __

And when I noticed, the date had changed completely at 1 am.

Day 3. Results of continued google

Ruby on Rails 5 --undefined method ʻimage_name'for nil: NilClass error | teratail

I arrived at the above site. From here, the citation continues,

![Screenshot 2020-09-09 16.20.17.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/688029/9207fcde-3ea3-61aa-649b -0533a6d40940.png)

This exchange is everything.

For those who do not want to read with many letters and small letters, to briefly summarize the conclusion, __ I've roughly grasped the cause, but it's better to recreate the database. __ The story.

__posts Create a table and enter multiple data ↓ Program in the middle to a rule that should not create columns in nil state (nothing) ↓ Create a new column (user_id) ↓ All user_id columns up to now are in the nil state ↓ Error occurred __

at the end

The cause contains data that should not be stored in the database. Then delete the data. Or if there is no problem even if you delete it in the database of the development environment, you can restore it by recreating it like this time.

In the case of Ruby on Rails,

Rails


$ rails db:drop #Delete database
$ rails db:create #Create a database
$ rails db:migrate #Migrate to database

If you enter the source code that suits your development environment in the same way as this, it's a good translation ^ ^

Recommended Posts

The idea of cutting off when the error is not resolved
[Rails] When the layout change of devise is not reflected
Error when the member of Entity class used in SpringWebFlux is final
ActiveSupport underscore is not the inverse of camelize
The devise error message is not displayed properly.
When the project is not displayed in eclipse
[Ruby] Meaning of &. How to avoid the error when the receiver (object) is nil
[Rails] What to do when the Refile image is not displayed when writing the processing at the time of Routing Error
The idea of quicksort
The idea of jQuery
When the hover of Eclipse is hard to see
When the month of the date is acquired, the January shift
[Error] The app is not displayed in the production environment
"tx" is not bound error
When an error occurs even though validation is not set
Error in production environment (The asset "~" is not present in the asset pipeline.)
When rewriting the CMD of docker image of Pod in the manifest of k8s, command is not good
[Swift] Get the timing when the value of textField is changed
[Eclipse] Version 1.8.0_261 of the JVM is not suitable for this product. Version: 11 or greater is required Error
Logback log is not output when the server application is closed
I want to make the frame of the text box red when there is an input error
About the solution to the problem that the log of logback is not output when the web application is stopped
The repository ... is not signed error in docker build apt-get update
The story that the build error did not stop when using Eclipse 2020
Investigation method when the CPU of the server running java is heavy
'% 02d' What is the percentage of% 2?
[RSpec] When you want to use the instance variable of the controller in the test [assigns is not recommended]
[Rails] About the error when displaying the screen due to the autofocus of the form
When the appearance of the input form is broken on the page after rendering
"" Application.js "is not present in the asset pipeline" error in Ruby on Rails
[Rails] About the error that the image is not displayed in the production environment
[Error] Regarding rbenv: ruby 2.5.1 is not installed ot ~ when executing automatic deployment
How to constrain the action of the transition destination when not logged in
When the form such as Select of Materialize does not work properly
Java / Kotlin: Calculate the quotient by specifying the number of significant digits when it is not divisible by the division (division) of BigDecimal.
How to resolve the error'ActionView :: Template :: Error (The asset "application.css" is not present in the asset pipeline.'" When precompiling Rails assets
[Rails] Annotate is not executed when migrating
What is testing? ・ About the importance of testing
[Ruby] Cut off the contents of twitter-ads
What is the data structure of ActionText?
About the error message Invalid redeclaration of'***'
When UITextView is not displayed (Swift, Xcode)
[swift] How to control the behavior when the back button of NavigationBar is pressed
Possibility when deploying to EC2 but nothing is displayed in the error log
[Thymeleaf & Spring] Error caused by not putting / at the end of meta tag
[Grails] Error occurred running What to do when the Grails CLI does not start
Upcast (Java) that can reduce the amount of change when the specification is changed
[Twitter API] Countermeasures when "It is not safe" appears on the https site
How to set when "The constructor Empty () is not visible" occurs in junit
The list of installed apps is not displayed in getPackageManager (Android11 ​​/ API level 30)
Is it mainstream not to write the closing tag of <P> tag in Javadoc?
Cause of is not visible when calling a method of another class in java
[Java] Calculate the day of the week from the date (Calendar class is not used)
When changing the Controller of Spring Web MVC to kotlin, @Autowired The specified component is not injected and becomes null.
When displaying a message with a JSF custom validator, the errorClass of h: message is not applied unless SEVERITY_ERROR is set in the message.