When I automatically deploy an app that works fine in the local environment, an error occurs in the production environment and the view is not displayed When it comes to that, I don't know what to do and I feel desperate. .. .. Please try it as one of the solutions in such a case.
Log in to ec2, manually type commands, and only drop and create the database. After that, the page can be displayed by using the automatic deployment of Capistrano to migrate.
After logging in to ec2, first execute the following code to delete and create the database in 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[0] -c /var/www/<%Application name%>/current/config/unicorn.rb -E production -D
kill -9 24327 //Enter process number 24327 for master
sudo service mysqld restart //Restart mysql
Finally return to your local terminal and auto-deploy `Migration is done at this point. ``
bundle exec cap production deploy
accomplished!
I haven't performed any special operations, but the point is to use the migrate function of capistrano. I don't know why this worked, but it looks like we'll still have to experiment with errors in production. .. ..
Recommended Posts