gpt4 book ai didi

ruby-on-rails - PG::错误:错误: ""处或附近的零长度定界标识符“”

转载 作者:行者123 更新时间:2023-11-29 11:26:37 25 4
gpt4 key购买 nike

我只是转储了我的暂存数据库,然后在我的本地 postgres 数据库上做了 pg_restore 以使它们排队。所有数据都通过了。

现在,当我尝试在 Rails 控制台中查询时,出现错误。

Artist.count
(0.5ms) SELECT COUNT(*) FROM "artists"
=> 668

**

Artist.last
Artist Load (1.4ms) SELECT "artists".* FROM "artists" ORDER BY "artists"."" DESC LIMIT 1
PG::Error: ERROR: zero-length delimited identifier at or near """"
LINE 1: ...T "artists".* FROM "artists" ORDER BY "artists"."" DESC LI...
^
: SELECT "artists".* FROM "artists" ORDER BY "artists"."" DESC LIMIT 1
ActiveRecord::StatementInvalid: PG::Error: ERROR: zero-length delimited identifier at or near """"
LINE 1: ...T "artists".* FROM "artists" ORDER BY "artists"."" DESC LI...
^
: SELECT "artists".* FROM "artists" ORDER BY "artists"."" DESC LIMIT 1
from /Users/ryanrebo/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `exec'

我在所有其他模型上都遇到了同样的错误。我也不能使用 find(id)

有什么想法吗?

最佳答案

错误发生是因为“artists”表没有用于排序的主键:

Artist Load (1.4ms) SELECT "artists".* FROM "artists" ORDER BY "artists"."" DESC LIMIT 1

通过将以下代码块添加到 Rails 迁移或在数据库中运行 alter table 命令来添加主键以修复:

execute <<-SQL ALTER TABLE assets ADD PRIMARY KEY (id); SQL

其中id是“artists”的主键。

关于ruby-on-rails - PG::错误:错误: ""处或附近的零长度定界标识符“”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31998594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com