我在我的Raspberry Pi上使用Postgresql 9.1运行了一个应用程序。
我的第一次迭代是将天气记录添加到名为" Weathers"的表中。那是成功的。
我的下一次迭代是使用psychopg2
将来自Python的记录写入另一个名为" weather"的表中。这也是成功的。
应该成功的是将我的应用中的Weather类更改为新字段。但DataMapper返回映射错误:
@records = Weather.all(:order => :timestamp.desc)
ArgumentError at /
+options [:order]+ entry :timestamp does not map to a property in Weather
重新阅读datamapper.org文档表明它与我的表名有关,所以我迁移过旧的"天气"把桌子变成了另一个名为“#34; old"并且放弃了#34;天气"表。但是DataMapper仍然无法找到这个表。
我的Postgres环境以及目标表的截断视图是:
List of relations
Schema | Name | Type | Owner
--------+-----------+-------+-------
public | customers | table | pi
public | older | table | pi
public | systemlog | table | pi
public | weather | table | pi
(4 rows)
Table "public.weather"
Column | Type | Modifiers | Storage | Description
-----------------------------+-----------------------------+------------------------------------------------------+----------+-------------
id | integer | not null default nextval('weather_id_seq'::regclass) | plain |
timestamp | timestamp without time zone | default now() | plain |
currentwindspeed | real | | plain |
bmp180temperature | integer | | plain |
Indexes:
"weather_pkey" PRIMARY KEY, btree (id)
Has OIDs: no
我的Datamapper类是:
class Weather
include DataMapper::Resource
property :id, Serial
property :bmp180temperature, String
property :insidehumidity, String
property :totalrain, String
property :currentwinddirection, String
property :currentWindSpeed, String
property :timestamp, DateTime
end
DataMapper.finalize
Weather.auto_upgrade!
由于这是Ruby我激发了IRb,需要Datamapper gem并得到:
records = Weather.all
DataObjects::SyntaxError: ERROR: column "bmp180temperature" does not exist
LINE 1: SELECT "id", "bmp180temperature", "insidehumidity", "totalra...
^
(code: 50360452, sql state: 42703, query: SELECT "id", "bmp180temperature", "insidehumidity", "totalrain", "currentwinddirection", "current_wind_speed", "timestamp" FROM "weathers" ORDER BY "id", uri: postgres:pi@localhost/postgres?scheme=postgres&user=pi&password=pw&host=localhost&port=&path=/postgres&query=&fragment=&adapter=postgres)
from /var/lib/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:147:in `execute_reader'
from /var/lib/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:147:in `block in read'
from /var/lib/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:276:in `with_connection'
这让我觉得它找不到合适的桌子。或许可以使用id
列。
我在CodeIgniter框架中看到似乎是用于PHP的DataMapper,但我不确定它是否与我在Ruby中使用的DataMapper相同。
为了让DataMapper找到这张表,我忽略了什么?