rake db:migrate 抛出 BusyException: 数据库已锁定异常

发布于 2024-10-27 06:24:41 字数 381 浏览 2 评论 0原文

我正在阅读 Michael Hartl 编写的 Ruby on Rails 教程,在第 6 章中,我被指示创建一个新的迁移,以向用户表中的电子邮件列添加索引。

这是我的迁移:

def self.up
  add_index :users, :email, :unique => true
end

def self.down
  remove_index :users, :email
end

当我运行 rake db:migrate 时,它​​会思考一秒钟,然后抛出一个 BusyException 并表示数据库已锁定。该数据库是一个 sqlite3 数据库,存储在我的本地计算机上的用户文件夹中;没什么特别的。

非常感谢任何和所有的帮助。

I'm going through the Ruby on Rails tutorial by Michael Hartl, and in chapter 6 I am instructed to create a new migration to add an index to the email column in the users table.

Here is my migration:

def self.up
  add_index :users, :email, :unique => true
end

def self.down
  remove_index :users, :email
end

When I run rake db:migrate it thinks for a second, then throws a BusyException and says the database is locked. The database is a sqlite3 database stored on my local machine in my user folder; nothing special.

Any and all help is greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

栩栩如生 2024-11-03 06:24:41

我一直都明白这一点,它在于这样一个事实:sqlite 一次只能由一个进程访问,并且数据库被该进程锁定。确保您没有在另一个终端中运行服务器或控制台。如果您继续收到此消息,并且您确定没有其他任何东西访问该 sqlite 数据库(包括僵尸进程),您可以按照此处的建议进行操作:

如何解锁 SQLite 数据库?

I get this all the time, it lies in the fact that sqlite can only be accessed by one process at a time and that the database is locked by that process. Be sure you have no servers or consoles running in another terminal. If you continue to get this, and you are sure there is nothing else accessing that sqlite database (including zombie processes), you can follow the advice here:

How do I unlock a SQLite database?

夜清冷一曲。 2024-11-03 06:24:41

几乎同样的事情也发生在我身上。
简单的解决方案是从我的 Rails 控制台退出。它正在锁定 SQLite。

Almost the same has happended to me.
The, simple, solution was exiting from my rails console. It was locking SQLite.

折戟 2024-11-03 06:24:41

我也有同样的问题。对我来说,我打开了 SQLite 数据库浏览器,并使用锁定它的相同数据库。

I had the same problem. For me I had the SQLite Database Browser open with the same database which was locking it.

独自←快乐 2024-11-03 06:24:41

/同意 Christopher

对于我们这些使用基于 UNIX 的机器的人来说,

$: ps -a | grep ruby
$: kill -s 9 XXXX

我怀疑是来自终端的一个简单的 ruby​​ 进程是罪魁祸首为我做的。它总是由控制台或服务器以某种方式挂起导致我杀死它,然后必须找到“僵尸”进程来解锁数据库。

当然,在 Windows 上,这不会比杀死可疑进程树更困难。

/agree with Christopher

For those of us on unix-based machines, a simple

$: ps -a | grep ruby
$: kill -s 9 XXXX

of ruby processes from terminals I suspected as the culprit did it for me. It was always caused by a console or server that hung in a way that made me kill it and then have to find the 'zombie' process to unlock the db.

On windows it can't be harder than killing a suspect process tree, surely.

玻璃人 2024-11-03 06:24:41

回想起来,“显而易见”的是,我的 BusyException 问题的解决方案是我没有对 SQLite3 数据库的写访问权限。我将一个 Rails 项目 git 克隆到了一个 Windows 服务的文件系统,我从 Ubuntu 盒子访问该文件系统。无论出于何种原因,Sqlite3 数据库都是使用 +x 权限创建的,Sqlite3 必须将其解释为繁忙。

只是在经过大量工作确认版本、宝石、红宝石等之后,我才注意到文件权限是+x。

诚然,这是一组神秘的情况,但我在这个问题上苦苦挣扎了两周,没有从谷歌搜索中找到任何帮助,我想我应该将解决方案添加到知识库中。

The solution to my BusyException problem, "obvious" in retrospect, was that I did not have write access to SQLite3 database. I had git clone'd a rails project to a windows-served file-system that I was accessing from a Ubuntu box. For whatever reason, Sqlite3 databases were created with +x permission which Sqlite3 must interpret as busy.

It was only after lots of work confirming versions, gems, rubies, etc, that I noticed files permissions were +x.

Granted, an arcane set of circumstances, but I struggled with the problem on/off for two weeks, without finding any help from searching Google, that I thought I would add solution to knowledge base.

情场扛把子 2024-11-03 06:24:41

对我来说,什么都不起作用。我删除了所有 *.sqlite3 文件,然后运行

rake db:create
rake db:migrate

然后它起作用了。

PS:sqlite3文件位于rails项目根目录的db文件夹中

For me, Nothing was working. I deleted all *.sqlite3 files and then ran

rake db:create
rake db:migrate

Then it worked.

PS: sqlite3 files are located in db folder of your root directory of rails project

呆° 2024-11-03 06:24:41

刚刚遇到了同样的问题,但解决方案与上面略有不同。

$ pgrep -l rails
XXXX ruby
$ kill -s 9 XXXX

Just had this same issue but the solution was slightly different than above.

$ pgrep -l rails
XXXX ruby
$ kill -s 9 XXXX
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文