从现有的 mysql 表在 rails 中创建迁移文件 [英] Create migration files in rails from existing mysql table

查看:39
本文介绍了从现有的 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 中创建迁移文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆