[RUBY] When registering a new user, I got an error called ActiveRecord :: NotNullViolation and how to deal with it.

Error in new user registration

I got the following error while implementing the user management function. 151aa02ffd6f364ebe9ba332e3ba4fde.png

About white error

ActiveRecord::NotNullViolation in Devise::RegistrationsController#create

If you look it up on a reference site

"This error is an error caused by saving an item that should not be NULL due to DB constraints."

There was.

What I confirmed

① Migration file

In the image error statement above

Mysql2::Error: Field 'prefecture_address' doesn't have a default value

So I checked the migration file to confirm this. Please see the image. 2d3be4158c0f509fdaaba70a1ae46896.png

There seems to be no problem here because it is set like that in the migration file.

② Controller

If it is set in the migration file, I think that the recipient may not have received it, so next check the controller. controller.png This was also the column name as specified in the migration file.

③ View

Now that I have migrated and controllered, I decided to check the view. (I'm a little impatient here.) The image of the view is as follows. 5bf9c8d818125e51fd7a384acda259f7.png Did you understand ... In the migration file and controller, it was prefecture_address, but in the view file, it was prefecture_address.

Code fix

When I finished modifying the view and made a new registration, I was able to register successfully.

Finally

Basically, when I get an error, I'm impatient with NoRoute Matches (I think I've overcome NoRoute Matches), so when I got an error I've never seen before, I thought, "Oh ... it's over ...". In this case, I didn't know which file the source code was referring to, so I wasn't rushed.

I was lucky to look into the error and hit the site. I will take this opportunity to add error tolerance. Excuse me.

References

【teratail】 Error when logging in / creating a new one by introducing the devise function https://teratail.com/questions/235508

Recommended Posts

When registering a new user, I got an error called ActiveRecord :: NotNullViolation and how to deal with it.
How to display error messages and success messages when registering as a user
I built a CentOS 8 environment with Vagrant and tried to sync_folder, but I got an error, so I solved it.
When I bcrypt with node + docker, I got an error
[Docker] How to update using a container on Heroku and how to deal with Migrate Error
I got an error when trying to install sbt to build a Scala development environment
I got an error when using nextInt, nextLine and substring.
Cases where Rails fails to start due to an invalid config/master.key and how to deal with it
I got an IllegalAccessError when trying to use PowerMock with JUnit
I got an error and couldn't push! !! [error: failed to push some refs to]
What to do and how to install when an error occurs in DXRuby 1.4.7
I want to display an error message when registering in the database
How to make an app with a plugin mechanism [C # and Java]
When I tried to start GlassFish, I got an internal error while "Publishing to GlassFish 4.0 on localhost ...". What to do when it becomes
[Laravel] How to deal with out of memory error when composer require [Docker]
I'm making an Android app and I'm stuck with errors and how to solve it
When I tried to use a Wacom tablet with ubuntu 20.04, I didn't recognize it.
I get an error when adding a dependency
I got an error when I ran rake routes.
How to delete the tweet associated with the user when you delete it at the same time
I called YouTube video from DB with haml and tried to embed and display it
[Ruby] 5 errors that tend to occur when scraping with Selenium and how to deal with them
Common problems with WSL and how to deal with them
[Java] How to start a new line with StringBuilder
A story stuck with an error when building Vagrant + Virtulbox CentOS7.8 and creating a shared folder
When trying to insert a specific gem (levenshtein) with Docker, an error occurred without ruby-dev
I can deploy to heroku, but I get an error and can't open it [Cause: MySQL]
When I did rails new, I got an error saying PG :: ConnectionBad: could not connect to server: No such file or directory
[Terraform] When I try to build an Azure resource on a Windows machine, it will time out, so I solved it with Docker.
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
How to specify db when creating an app with rails
I got an InvalidUseOfMatchersException when using any with JUnit Mock
How to deal with the error ERROR: While executing gem ... (Gem :: FilePermissionError)
How to deal with different versions of rbenv and Ruby
How to deal with the type that I thought about writing a Java program for 2 years
Memorandum: When I tried TensorFlow with Tribuo, it didn't work, so I went on a journey to find the head family and lost.
[Rails / RSpec] How to deal with element has zero size error
How to deal with 405 Method Not Allowed error in Tomcat + JSP
I get a 404 error when testing forms authentication with Spring Security
I get a Ruby version error when I try to start Rails.
I got a warning message with the rails _6.0.3_ new hello_myapp command
How to read a file and treat it as standard input
I got a Permission Denied error when I put Laravel in Docker
[Introduction to JSP + Servlet] I played with it for a while ♬
I got stuck trying to write a where in clause in ActiveRecord
How to set the default fetch size when jOOQ gets an OOM error when fetching a huge result set
I want to download a file on the Internet using Ruby and save it locally (with caution)
When I tried to build an environment of PHP7.4 + Apache + MySQL with Docker, I got stuck [Windows & Mac]
What I did when I was addicted to the error "Could not find XXX in any of the sources" when I added a Gem and built it