从现有的 mysql 表在 rails 中创建迁移文件

编程入门 行业动态 更新时间:2024-10-27 18:20:45
本文介绍了从现有的 mysql 表在 rails 中创建迁移文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在用 rails 开发一个应用程序.我在 mysql 中创建了一个表,上面写着学生".无论如何要在 rails 应用程序中创建它的迁移文件?我已经在 config/database.yml" 中指定了数据库名称并使用其他表.但我想创建表迁移文件.我该怎么做?

I m developing an application in rails. I have created a table say "student" in mysql. Is there anyway to create its migration file in rails application? I have specified databse name in config/database.yml" and using others table too. But i want to create tables migration file. How can i do it?

推荐答案

  • 首先在 database.yml 中引用您现有的 MySQL 数据库
  • 运行 rake db:schema:dump 以生成 schema.rb 文件
  • 将 create_table 方法从 schema.rb 粘贴到新的迁移中,瞧!
    • Start by referencing your existing MySQL database in database.yml
    • run rake db:schema:dump to generate the schema.rb file
    • Paste the create_table methods from your schema.rb into a new migration, and Voila!

更多推荐

从现有的 mysql 表在 rails 中创建迁移文件

本文发布于:2023-10-20 12:56:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1511028.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   mysql   rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!