使用现有的Mysql数据库构建Ruby on Rails App [英] Building Ruby on Rails App with an existing Mysql db

查看:66
本文介绍了使用现有的Mysql数据库构建Ruby on Rails App的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Mysql数据库,其中包含大量数据和表.但是我需要知道如何在我的新Rails应用程序中使用此Mysql数据.从现在开始我一直在学习Rails.我知道创建脚手架的基础知识,而脚手架又可以创建模型和控制器,但是我不清楚如何导入数据库并使用它. 谁能解释或为我提供有关如何解决此问题的链接.

I have a Mysql database with a large amount of data and tables. But i need to know how to use this Mysql data in the my new rails application. I've been learning Rails from a little time now. i know the basics of creating a scaffold which in turn creates models and controllers, but i'm unclear how to import a DB and use it. Can anyone explain or provide me with a link on how to get over this.

这是我运行一个简单的脚手架后的迁移,并且在其中添加了电子邮件字符串之后我没有运行rake db:migrate..

This is my migration after running a simple scaffold and i ran rake db:migrate after adding an email string there and nothing happened..:

class CreateProducts < ActiveRecord::Migration
  def change
    create_table :products do |t|
      t.string :title
      t.text :description
      t.string :image_url
      t.decimal :price, :precision => 8, :scale => 2
>>    t.string :email
      t.timestamps
    end
  end
end

推荐答案

如果您需要将数据从当前数据库导入应用程序数据库,建议使用

If you need to import that data from your current database into the one for your app, I recommend using Sequel Pro. It's a great GUI for MySQL. You can use it to export the database you want, say as a .csv file, and import it into your new database.

关于迁移,运行脚手架并运行rake db:migrate只会设置数据库.它不会添加任何数据.因此,在这里,已将其设置为创建products表,并为其属性指定了数据类型.

Regarding your migration, running a scaffold and running rake db:migrate will just set your database up; it won't add any data. So here, you've set it to create your products table, and specified the data types for its attributes.

但是要在其中获取数据,您只能通过应用程序中的表单或导入数据来实现.

But in order to get data in there, you can only do that via a form with your application, or by importing data.

这篇关于使用现有的Mysql数据库构建Ruby on Rails App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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