运行 rake 迁移时遇到 postgres 错误

发布于 2025-01-07 04:49:06 字数 967 浏览 1 评论 0原文

我在运行以 postgres 作为后端的 Rails 应用程序时收到以下 uuid 错误。有人可以帮我解决需要哪种依赖吗?

 [root@localhost webapp]# rake db:migrate
    (in /root/mysite/webapp)
    ==  CreateContributors: migrating =============================================
    -- create_table(:contributors, {:id=>false})
       -> 0.0121s
    -- execute("alter table contributors add primary key (id)")
    NOTICE:  ALTER TABLE / ADD PRIMARY KEY will create implicit index "contributors_pkey" for table "contributors"
       -> 0.0797s
    -- execute("alter table contributors alter column id set default uuid_generate_v1()::varchar")
    rake aborted!
    An error has occurred, this and all later migrations canceled:

    PGError: ERROR:  function uuid_generate_v1() does not exist
    HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
    : alter table contributors alter column id set default uuid_generate_v1()::varchar

I am getting the following uuid error while running a rails app with postgres as backend. Can someone help me out with which dependency is needed.

 [root@localhost webapp]# rake db:migrate
    (in /root/mysite/webapp)
    ==  CreateContributors: migrating =============================================
    -- create_table(:contributors, {:id=>false})
       -> 0.0121s
    -- execute("alter table contributors add primary key (id)")
    NOTICE:  ALTER TABLE / ADD PRIMARY KEY will create implicit index "contributors_pkey" for table "contributors"
       -> 0.0797s
    -- execute("alter table contributors alter column id set default uuid_generate_v1()::varchar")
    rake aborted!
    An error has occurred, this and all later migrations canceled:

    PGError: ERROR:  function uuid_generate_v1() does not exist
    HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
    : alter table contributors alter column id set default uuid_generate_v1()::varchar

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

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

发布评论

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

评论(1

萌︼了一个春 2025-01-14 04:49:07

uuid_generate_v1() 函数是 uuid 的一部分-ossp package 并且你必须将其安装到 PostgreSQL 中才能使用它。您的 PostgreSQL contrib 目录中应该有一个名为 uuid-ossp.sql 的文件。您可以通过以下方式安装该软件包:

$ psql -d your_database < /the/path/to/uuid-ossp.sql

您可能希望以数据库超级用户身份运行该软件包。

The uuid_generate_v1() function is part of the uuid-ossp package and you have to install that into PostgreSQL before you can use it. You should have a file called uuid-ossp.sql in your PostgreSQL contrib directory. You can install the package with:

$ psql -d your_database < /the/path/to/uuid-ossp.sql

You'll probably want to run that as the database super user.

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