postgresql PG::Error: ERROR: 零长度分隔标识符位于或靠近 """"
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31998594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PG::Error: ERROR: zero-length delimited identifier at or near """"
提问by Ryan Rebo
I just did a dump of my staging databse, than did pg_restore on my local postgres databse to get them to line up. All the data went through.
我只是转储了我的暂存数据库,而不是在我的本地 postgres 数据库上转储 pg_restore 以使它们排队。所有的数据都通过了。
Now when I try to query in the Rails console, I get errors.
现在,当我尝试在 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'
I get the same error on all other Models. I also cannot use find(id)
.
我在所有其他模型上遇到相同的错误。我也无法使用find(id)
.
Any ideas?
有任何想法吗?
回答by Ryan Rebo
I fixed this by dropping and then re-creating the local database, re-running the migrations, and passing --data-only
as an option on pg_restore
.
Thanks for the help y'all. That was a strange error.
我通过删除然后重新创建本地数据库、重新运行迁移并--data-only
作为pg_restore
. 谢谢大家的帮助。那是一个奇怪的错误。
回答by Trang Tung Nguyen
The error occurs because "artists" table does not have a primary key which is used for the order by:
发生错误是因为“艺术家”表没有用于订单的主键:
Artist Load (1.4ms) SELECT "artists".* FROM "artists" ORDER BY "artists"."" DESC LIMIT 1
艺术家加载 (1.4ms) SELECT "artists".* FROM "artists" ORDER BY "artists"."" DESC LIMIT 1
Add a primary key to fix by adding the following code block to a rails migration or run the alter table command in the database:
通过将以下代码块添加到 rails 迁移或在数据库中运行 alter table 命令来添加要修复的主键:
execute <<-SQL ALTER TABLE assets ADD PRIMARY KEY (id); SQL
执行 <<-SQL ALTER TABLE assets ADD PRIMARY KEY (id); 查询语句
where id is the primary key of "artists".
其中 id 是“艺术家”的主键。
回答by Ryan Rebo
What you did is kinda patch. It is not what you want to do when you have a dump. You should run
你所做的是有点补丁。当您有转储时,这不是您想要做的。你应该跑
1) rake db:drop
1) 耙 db:drop
2) rake db:create
2)耙分贝:创建
3) dump your data with pg_restore and no need in --data-only
3) 用 pg_restore 转储你的数据,不需要 --data-only