Rails Tutorial (M.Hartl) 3rd Edition, Chapter 8, How to unlock a database by closing a rogue `rails console`?

不羁岁月 提交于 2019-12-13 07:37:40

问题


I am in chapter 8.4.1, after generating a migration I tried running:

$ bundle exec rake db:migrate

But was given the following error:

rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::BusyException: database is locked:

#followed by a long list of paths/filenames and line numbers...

I know this is probably because I exited a terminal without properly exiting a rails console --sandbox session. But how do I find and close this rails console session?


回答1:


In your terminal console type (making sure you are in your Rails app directory):

$ ps aux

Then you should see a list of processes, amongst them something similar to:

USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
ubuntu     49527  0.0  0.0 482924   620 ?        Sl   Jan29   0:00 rails_console --sandbox

Take a note of the PID, in this case 49527, then run the following in the command line:

$ kill 49527

Now running your migration $ bundle exec rake db:migrate should work.




回答2:


try running $ ps aux | grep rails from the terminal.

should return something like this:

username   68924   0.0  1.5  3166032  62168   ??  S     8:49PM   0:00.16 rails_console    
username   68900   0.0  0.1  2472884   3420 s003  S+    8:48PM   0:00.62 /Users/username/.rbenv/versions/2.2.2/bin/ruby bin/rails c
username   68708   0.0  0.2  2535772   6396 s000  S+    8:20PM   0:03.16 /Users/username/.rbenv/versions/2.2.2/bin/ruby bin/rails s

Since the process has to be killed in this case, try to kill it forcefully with the command

$ kill -9 PID



来源:https://stackoverflow.com/questions/35156280/rails-tutorial-m-hartl-3rd-edition-chapter-8-how-to-unlock-a-database-by-clo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!