[英]Create new database table ruby on rails schema.rb
在我的ruby on rails应用程序上,我在schema.rb文件中添加了以下代码以在数据库中创建新表
create_table "label_info", :force => true do |t|
t.text "body"
t.string "title"
t.integer "label_id"
end
然后运行rake db:migrate命令,但没有任何反应。 我以为它将在数据库中创建一个新表。
如果您阅读schema.rb
文件的第一行,则会看到:
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
我会建议做rails g model label_info
可能是delete :force => true
,因为既然还没有创建表,它就一直先创建。
:force设置为true可以在创建表之前删除它。 默认为false。
对于旧的模式版本,您要么必须销毁模型并重新创建模型,要么必须更改迁移号并重命名文件。 您可以使用当前时间戳。 像20150808114518_abc_xyz.rb
谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.