Rails使用迁移文件生成模型

Har*_*M V 3 mysql ruby-on-rails ruby-on-rails-4

我创建了数据建模并导入了sql文件,并为我的所有模型生成了模式,如下所示.现在我想在MySQl中为我的所有表生成模型而没有迁移文件.

此外,我有两个名称镜,并希望对所有具有不同名称镜头的控制器使用相同的模型.

# Create a new Rails Project
rails new <project-name> -d mysql

# Run Bundler
bundle install

# Database Initiation
rake db:create

# Dump SQL file into MySQL
mysql -u hmv -p <database-name> < <database-file>

# Generate SQL Schema from the MySQL tables
rake db:schema:dump

# Creating a Git Repo for Versioning and Collaboration
git init
git remote add origin https://<Username>:<Password>@bitbucket.org/harshamv/<Project-Name>.git
git add .
git commit -m 'Initial commit'
git push -u origin master

# Create the Initial Migration File
rails generate migration initial_schema_dump

# Copy the Content from the Schema file to the migration file and run the following command
rake db:migrate 
Run Code Online (Sandbox Code Playgroud)

San*_*osh 5

您可以使用该--skip_migration选项

rails g model MyModel --skip_migration
  invoke      active_record
  create      app/models/my_model.rb
  invoke      test_unit
  create      test/models/my_model_test.rb
  create      test/fixtures/my_models.yml
Run Code Online (Sandbox Code Playgroud)