Rails 使用 MS SQL 服务器数据库 [英] Rails use MS SQL server database

查看:41
本文介绍了Rails 使用 MS SQL 服务器数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 rails 应用程序中,我需要使用现有的 MS SQL 数据库.我已尝试遵循本手册:

In my rails app, I need to use an existing MS SQL database. I have tried following this manual:

http://rubyrailsandwindows.blogspot.com/2008/03/rails-2-and-sql-server-2008-on-windows_24.html

我不知道如何做模型、脚手架等,因为 rails 不能简单地使用另一个数据库.我不想为 MS SQL 数据库中的表运行 rake db:migrate.我还需要在模型中写什么?如果简单:使用 MS SQL 服务器数据库中的表,但我也想解决迁移等问题.

I do not know how to do models, scaffolds, etc because rails cannot simply use another db. I didn't want to run rake db:migrate for my tables in the MS SQL database. What else do I need to write in the model? If simple: use tables from the MS SQL server's database, but I also want to solve problem with migrations, etc.

推荐答案

如果您需要在现有数据库之上运行 Rails,并且希望确保可以创建与现有表匹配的所有模型,请遵循本指南:

If you need to run your Rails up on top of the existing database and you want to make sure you can create all models that match existing tables, follow this guide:

  • Dump the schema into schema.rb using http://guides.rubyonrails.org/migrations.html#schema-dumping-and-you. I would actually use SQL mode of schema (config.active_record.schema_format = :sql ) and just use SQL Server tools to generate SQL file of the database schema and preserve it as db/structure.sql
  • After the database schema has been established, you can redirect tables and primary keys in your models using an approach outlined here: Putting Rails over top of an existing database

作为 ActiveRecord 的替代品,您可以考虑使用 DataMapper,因为它声称与 "棕地"(即已经建立的)数据库.

As an alternative to ActiveRecord altogether, you might consider DataMapper as it claims to work better with "brownfield" (i.e. already established) databases.

这篇关于Rails 使用 MS SQL 服务器数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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