简体   繁体   中英

Create new database table ruby on rails schema.rb

On my ruby on rails app i added following code in schema.rb file to create a new table in database

create_table "label_info", :force => true do |t|
    t.text     "body"
    t.string   "title"
    t.integer  "label_id"
  end

and then run rake db:migrate command but nothing is happening. I thought it would create a new table in database .

If you read the first line of your schema.rb file you will see:

# 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.

I would recommand to do rails g model label_info

May be delete :force => true , because since you haven't created the table it keeps to create first.

:force Set to true to drop the table before creating it. Defaults to false.

Either you have to destroy the model and recreate it or you have to change the migration number and rename the file, for the older schema version. You can use current time stamp. like 20150808114518_abc_xyz.rb

Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM