Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Datamapper-可能不是空错误_Ruby_Datamapper - Fatal编程技术网

Ruby Datamapper-可能不是空错误

Ruby Datamapper-可能不是空错误,ruby,datamapper,Ruby,Datamapper,我在一个简单的应用程序中使用DataMapper来跟踪销售。我有一天的课,像这样: class Day include DataMapper::Resource property :id, Serial, :key => true property :date, DateTime property :bestseller, String property :total_money, Decimal property :total_sold

我在一个简单的应用程序中使用DataMapper来跟踪销售。我有一天的课,像这样:

class Day
include DataMapper::Resource

property :id,            Serial, :key => true
property :date,          DateTime
property :bestseller,    String
property :total_money,   Decimal
property :total_sold,    Integer
property :total_orders,  Integer

has n, :sales

end
销售
课程:

class Sale
include DataMapper::Resource

belongs_to :day

property :id,     Serial, :key => true
property :name,   String
property :amount, Integer
property :value,  Integer
end
尝试向数据库添加新的
Sale
时,如下所示:

s = Sale.new(:day => Day.get(1), :name => "Foo", :amount => "42", :value => "42"
调用
save
时出现此错误

DataObjects::IntegrityError at /sell
sales.date may not be NULL
我在
Sale
中没有
date
属性,所以我不确定这是从哪里来的。首先,我认为我得到的
Day
对象没有设置日期,所以我做了
d=Day.get(1).date=Time。现在
保存它,但这并不能解决错误

我打碎了什么

编辑sqlite3架构

CREATE TABLE "sales" (
  "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
  "name" VARCHAR(50), 
  "amount" INTEGER,
  "value" INTEGER, 
  "day_id" INTEGER NOT NULL,
  "drink_id" INTEGER NOT NULL
);
CREATE INDEX "index_sales_day" ON "sales" ("day_id");
CREATE INDEX "index_sales_drink" ON "sales" ("drink_id");

我想我修好了。显然,我在
销售
的某一点上有一处旧的
日期
房产。我进入ruby解释器,需要我的模型并使用
DataMapper.auto\u migrate
重置整个数据库。这解决了问题。

错误语法看起来可能来自数据库。你能进入数据库控制台检查模式(在这里发布)吗?我该怎么做?我忘了提到,数据库是SQLite3。只需在控制台上键入
SQLite3
,然后在中键入
.schema sales
.help
获取帮助,
.quit
退出。如果这是生产数据,请避免执行任何其他操作(尽管您可以使用该文件的副本)@NeilSlater我添加了模式。检查编辑。谢谢。关于与此相关的模式,似乎我错了,没有
sales.date
列。然而,它是有用的信息,因此值得留在问题中。