---
title: "建立已经存在数据库的Rails项目常用命令"
author: "kenrome"
date: "2009-08-11T22:12:32Z"
tags: []
slug: "rails"
draft: false
lastmod: "2009-08-11T22:14:39Z"
id: 445105
url: "https://inruby.iteye.com/blog/445105"
---

创建不需要迁移文件的Model:
> ruby script/generate model Community --skip-migration

在Model中指定表名，主键

```java

 class Community < ActiveRecord::Base
   set_table_name 'communities'
   set_primary_key :community_id
   has_many :games, :foreign_key => 'div_id'
 end

```