db:migrate 在简单迁移上挂起

发布于 2024-12-28 18:33:01 字数 1437 浏览 0 评论 0原文

我正在使用 PostgreSQL、Rails 3.1.3 和 Ruby 1.9.3。我正在努力使用 db:migrate 概述 此处

这就是我在终端中看到的:

funkdified@funkdified-laptop:~/railsprojects/hartl$ bundle exec rake db:migrate --trace 
** Invoke db:migrate (first_time) 
** Invoke environment (first_time) 
** Execute environment 
** Invoke db:load_config (first_time) 
** Invoke rails_env (first_time) 
** Execute rails_env 
** Execute db:load_config 
** Execute db:migrate 
== AddEmailUniquenessIndex: migrating ======================================== 
-- add_index(:users, :email, {:unique=>true})

然后代码此时挂起。有什么想法吗?

来自:development.log

[1m[36m (0.1ms)[0m [1mSHOW search_path[0m 
[1m[35m (0.5ms)[0m SELECT "schema_migrations"."version" FROM "schema_migrations"
Migrating to CreateUsers (20120124022843) 
Migrating to AddEmailUniquenessIndex (20120124093922) 
[1m[36m (0.1ms)[0m [1mBEGIN[0m 
[1m[35m (3.6ms)[0m SELECT distinct i.relname, d.indisunique, d.indkey, t.oid 
FROM pg_class t 
INNER JOIN pg_index d ON t.oid = d.indrelid 
INNER JOIN pg_class i ON d.indexrelid = i.oid 
WHERE i.relkind = 'i' 
AND d.indisprimary = 'f' 
AND t.relname = 'users' 
AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = ANY (current_schemas(false)) ) 
ORDER BY i.relname

I am using PostgreSQL, Rails 3.1.3 and Ruby 1.9.3. I am struggling to use db:migrate as outlined here.

This is what I am seeing in the terminal:

funkdified@funkdified-laptop:~/railsprojects/hartl$ bundle exec rake db:migrate --trace 
** Invoke db:migrate (first_time) 
** Invoke environment (first_time) 
** Execute environment 
** Invoke db:load_config (first_time) 
** Invoke rails_env (first_time) 
** Execute rails_env 
** Execute db:load_config 
** Execute db:migrate 
== AddEmailUniquenessIndex: migrating ======================================== 
-- add_index(:users, :email, {:unique=>true})

and then the code hangs at this point. Any ideas why?

From: development.log

[1m[36m (0.1ms)[0m [1mSHOW search_path[0m 
[1m[35m (0.5ms)[0m SELECT "schema_migrations"."version" FROM "schema_migrations"
Migrating to CreateUsers (20120124022843) 
Migrating to AddEmailUniquenessIndex (20120124093922) 
[1m[36m (0.1ms)[0m [1mBEGIN[0m 
[1m[35m (3.6ms)[0m SELECT distinct i.relname, d.indisunique, d.indkey, t.oid 
FROM pg_class t 
INNER JOIN pg_index d ON t.oid = d.indrelid 
INNER JOIN pg_class i ON d.indexrelid = i.oid 
WHERE i.relkind = 'i' 
AND d.indisprimary = 'f' 
AND t.relname = 'users' 
AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = ANY (current_schemas(false)) ) 
ORDER BY i.relname

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

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

发布评论

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

评论(4

亽野灬性zι浪 2025-01-04 18:33:01

我刚刚遇到了类似的问题,一个非常简单的迁移由于没有明显的原因而停滞不前。我认为问题与无法获得数据库连接有关。我退出了在另一个终端中打开的 Rails 控制台会话,然后迁移立即完成,没有任何问题。

I just had a similar problem, where a very simple migration was stalling for no apparent reason. I believe the problem has to do with not being able to get a database connection. I exited a rails console session that I had open in another terminal and then the migration immediately finished with no problems.

埖埖迣鎅 2025-01-04 18:33:01

我遇到了同样的问题..我发现有空闲事务阻止了对该表的进一步查询..

运行:

heroku pg:ps --app=...

查看数据库进程。您必须终止空闲进程:

heroku pg:kill 913 --force --app=...

(913 是空闲进程的 ID -> 将其更改为您的需要)

I had same problem .. I found out that there was idle transaction which blocked further queries on this table ..

Run:

heroku pg:ps --app=...

To view database processes. You will have to kill idle process:

heroku pg:kill 913 --force --app=...

(913 is ID of idle process -> change it to your needs)

乖乖公主 2025-01-04 18:33:01

我遇到了同样的问题,在尝试了一系列解决方案后,有效的方法是...关闭所有终端会话,重新启动计算机,然后重试。有时这只是电源循环魔法。

I had the same issue and after trying a bunch of solutions what worked was...shutting down all of my terminal sessions, restarting the computer, and trying again. Sometimes it's just power cycle magic.

庆幸我还是我 2025-01-04 18:33:01

我刚刚进行了两次迁移。第一个创建了一个新表,第二个从现有表中删除了字段。第二次迁移挂起,原因是 Rails 控制台会话 (rails console --sandbox) 在另一个终端窗口中运行。

I just made two migrations. The first one created a new table, the second one removed fields from an existing table. The second migration was hanging, and the reason turned out to be a rails console session (rails console --sandbox) running in another terminal windows.

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