zoukankan      html  css  js  c++  java
  • rails 字段的增删改命令 model和数据库的删除

    1、其实rails c 控制台每次读取的都是model里的文件且不会自动更新,所以增加字段时,要在在model文件里面先写上字段,然后重启rails c 才能查到该字段

    2、 增加字段: rails  g migration add_column_to_model 字段名:类型

         然后迁移任务, 之后想再该model 里添加字段,不会成功,因为提醒迁移文件已存在,所以只能删除字段

          rails g migrationk remove_column_from_model 字段名 再着是要删除之前的迁移文件

         再次添加两个字段,执行迁移任务, 事情总有对立性,第二次删除字段,需要先把第一个删除字段的迁移文件取出,不然会提示

    Another migration is already named ,执行玩后运行rake db:migrate 执行迁移任务。

    3、model的删除执行rails destroy model model的名字

         这样执行 后虽然在控制台上查不到该数据表了,但在数据库里它还是没被修改的,进入数据库把表删除,才真正删除数据表

  • 相关阅读:
    Search Insert Position
    Substring with Concatenation of All Words
    Swap Nodes in Pairs
    Remove Element
    Remove Duplicates from Sorted Array
    Letter Combinations of a Phone Number
    Remove Nth Node From End of List
    Valid Parentheses
    Merge k Sorted Lists
    Using an Interface as a Type
  • 原文地址:https://www.cnblogs.com/chenzhenzhen/p/3945694.html
Copyright © 2011-2022 走看看