awesome_nested_set gem lft没有默认

时间:2018-02-23 23:05:15

标签: awesome-nested-set

嘿伙计们我第一次尝试使用ruby awesome_nested_set gem。

我在rails-api应用程序中遇到了我的minitests问题。我知道问题是什么,但我不确定如何解决这个问题。

当我运行“rails test”时,我收到一堆类似于以下内容的错误: StoresControllerTest#test_should_create_store: ActiveRecord :: StatementInvalid:Mysql2 :: Error:字段'lft'没有默认值:INSERT INTO categories(name,created_at,updated_at,id,store_id)VALUES('MyString','2018-02-23 03: 08:13','2018-02-23 03:08:13',980190962,980190962)

这是我的迁移: class AddLftToCategory< ActiveRecord :: Migration [5.0] def change add_column:categories,:lft,:integer,:null => false add_index:categories,:lft end end

我认为问题是由于我的迁移设置“:lft,:null => false。这是最有意义的,但我该如何解决这个问题?我需要在我的夹具上添加一些东西,或者是还有别的我必须做的吗?

感谢。

1 个答案:

答案 0 :(得分:0)

在阅读gem的文档后,很明显您的迁移不完整。你的类别需要有一个:rgt列以及:lft,:name和:parent_id,以便gem工作。请参阅此处的文档:(https://github.com/collectiveidea/awesome_nested_set/blob/master/README.md)。您还需要将acts_as_nested_set添加到模型中,以便宝石填充这些字段。