I'm currently developing a web app with ruby on rails, but I have a question about validation.
Is it possible to perform conditional mandatory checks in the migration file?
It seems that the model class can perform conditional mandatory checks, but when I checked the official documentation in the migration file, it seems that it is not described, so is there such a method?
In addition, both the model and the migration file can be validated such as mandatory checks, but the model is checked on the AP server and the migration file is checked on the DB server. Basically, the migration file is checked. Is it correct to recognize that the check with complicated conditions like this time is performed by the model?
I would like somebody to teach.
Rails Guide Active Record MigrationSupplementary information (FW/tool version, etc.)
Answer # 1
I wasn't familiar with it so I was watching it, but ...
As far as I know, I've never seen a condition for a not null option in a database.
There is a good point and another point in which one to perform the required check.
If you do it with validation, it is easy because you can display the error message within the Rails frame.
However, it is possible to create nul data with raw SQL.
Also, the data created before setting validation may still be null, and I've seen a number of examples where it's bad.
If you do it in DB, there will be no null data.
But putting the error in the error message can be awkward.
- ruby on rails 6 - about validation (number of characters) of rails tweet posting
- ruby on rails - [rails6] i want to display the validation error generated by update by index
- about description of manifest file of ruby on rails
- [ruby on rails] about header setting using bootstrap
- ruby - [rails] about errors when installing bootstrap
- ruby on rails - rails render: about the matter that the url after new is different
- ruby on rails - about image posting page argumenterror
- ruby on rails - about passing view and controller data with rails
- ruby on rails 5 - about lint/syntax error of rubocop
- ruby - about accelerating heroku's rails app
- ruby - about the delete function in rails
- ruby on rails - about switching screen display on multiple models
- ruby on rails - about screen transition from rails top page to calendar page
- ruby on rails - [rails] about the problem that screen transition is not possible (error does not occur)
- ruby on rails - about the matter that does not transition to the detail page
- ruby on rails - about the description in applicationjs
- ruby on rails - rspec conditional validation
- ruby - about routing using rails collection
- ruby on rails - about image distribution on heroku and s3
- html - i want to allow users to use points
- ruby - about implementation of tag function in rails
- ruby - how to upload images directly from rails to s3 on aws
- ruby - an error occurred when implementing the micropost search function using ransack
- ruby - i want to replace a specific value in a column of multiple records
- ruby - the value is not assigned successfully
- ruby - when i run rails s, i get a message like error loading the'sqlite3' and the server doesn't start properly
- ruby - i want to postico the db in the docker container of the local environment
- ruby - items duplicated by cocoon are caught in forbid_login_user and are not saved