When automatically deploying an application that worked without problems in the local environment, an error occurred in the production environment and the view was not displayed It makes me feel hopeless without knowing what to do. .. .. ![Screenshot 2020-08-17 8.01.24.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/603218/327fd7c0-b9e2-b83f-8605-(395f7351f4b0.png) In such a case, please try it as one of the solutions.
Conclusion: drop, create manually, migrate automatically
Log in to ec2 and manually enter commands to drop and create databases. After that, the page can be displayed by migrating with automatic deployment of Capistrano.
After logging in to ec2, first execute the following code to delete and create the database on the production environment.
cd /var/www/<%application name%> cd current rails db:drop RAILS_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1 rails db:create RAILS_ENV=production
After that, restart unicorn and mysql. (Long code on the right)
ps aux |grep unic //Execution result (number is different) ec2-user 24327 0.1 11.5 504288 116388 ?Sl 22:46 0:02 unicorn master -c /var/www/<%application name%>/current/config/unicorn.rb -E production -D ec2-user 24334 0.0 12.3 651728 124368 ?Sl 22:46 0:00 unicorn worker -c /var/www/<%application name%>/current/config/unicorn.rb -E production -D kill -9 24327 // enter process number 24327 of master sudo service mysqld restart // restart mysql
Finally return to the local terminal and auto deploy
Migration is done at this point.
bundle exec cap production deploy
I do not do any special operation, but the point is to use the migrate function of capistrano. I’m not sure why this worked, but I’m sure we’ll have to experiment with errors in production. .. ..