从现有表生成活动记录模式 [英] generate activerecord schema from an existing table
本文介绍了从现有表生成活动记录模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道这样做的方法吗?
Does anyone know of a way to do this?
我有一个用 sql 创建的现有表,我想从中创建一个模式来重现该表(减去数据)
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)
推荐答案
- 编辑 config/database.rb 以指向您要复制的数据库.
rake db:schema:dump
- 创建一个空白迁移
- 从架构转储中复制相关的
create_table
行并将其粘贴到迁移文件中 - 手动将迁移时间戳插入 schema_migrations 表(这仅适用于现有设置,因为它已经具有相关表)
- Edit config/database.rb to point to the database you want copied.
rake db:schema:dump
- Create a blank migration
- Copy the relevant
create_table
lines from the schema dump and paste it into the migration file - Manually insert the migration timestamp into schema_migrations table (this applies to existing setup only as it already has the relevant table)
这篇关于从现有表生成活动记录模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文