从现有的表生成的ActiveRecord模式 [英] generate activerecord schema from an existing table

查看:114
本文介绍了从现有的表生成的ActiveRecord模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道的一种方式做到这一点?

我有我与SQL创建了一个现有的表,我想创建一个从它的模式,将重现表(减去数据)

解决方案
  1. 编辑配置/ database.rb指向你想复制的数据库。
  2. 耙分贝:模式:转储
  3. 创建一个空白的迁移
  4. 从模式转储复制有关 CREATE_TABLE 行并将其粘贴到迁移文件
  5. 在手动插入迁移时间戳到schema_migrations表(适用于只因为它已经有相关的表现有设置)

Does anyone know of a way to do this?

I have an existing table that I created with sql and I would like to create a schema from it that would reproduce the table (minus the data)

解决方案

  1. Edit config/database.rb to point to the database you want copied.
  2. rake db:schema:dump
  3. Create a blank migration
  4. Copy the relevant create_table lines from the schema dump and paste it into the migration file
  5. Manually insert the migration timestamp into schema_migrations table (this applies to existing setup only as it already has the relevant table)

这篇关于从现有的表生成的ActiveRecord模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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