所以一切都在我的项目上工作到了这一点,即6.0添加第二个模型。我做了
rails generate model Comment commenter:string body:text article:references
这会生成我打开并查看的正确文件。
app/models/comment.rb
和迁移文件
_create_comments.rb
(我遗漏了日期戳)
当我运行rake db:migrate
时,我收到以下错误:
== 20150709191058 CreateComments: migrating ===================================
-- create_table(:comments)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
private method `test' called for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x007fe7984adf58>/Users/johnlarkin/Sites/blog/db/migrate/20150709191058_create_comments.rb:5:in `block in change'
/Users/johnlarkin/Sites/blog/db/migrate/20150709191058_create_comments.rb:3:in `change'
NoMethodError: private method `test' called for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x007fe7984adf58>
/Users/johnlarkin/Sites/blog/db/migrate/20150709191058_create_comments.rb:5:in `block in change'
/Users/johnlarkin/Sites/blog/db/migrate/20150709191058_create_comments.rb:3:in `change'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
在处理这个项目时有没有人遇到过类似的错误我刚刚开始学习ruby和rails。
感谢您的帮助。
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.string :commenter
t.test :body
t.references :article, index: true
t.timestamps null: false
end
add_foreign_key :comments, :articles
end
end
答案 0 :(得分:1)
我认为你在rails generate命令中键入了“test”而不是“text”。您可以删除所有新文件并重新开始,或将“t.test”更改为“t.text”。