本文介绍了从现有的 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 中创建迁移文件
发布评论