【问题标题】:Rails Generate Model with out Migration FilesRails 生成没有迁移文件的模型
【发布时间】:2014-11-28 05:42:17
【问题描述】:

我已经创建了数据建模并导入了 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 

【问题讨论】:

    标签: mysql ruby-on-rails ruby-on-rails-4


    【解决方案1】:

    您可以使用--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
    

    【讨论】:

    • 有没有办法从 Schema 中的所有表中批量生成这个?
    • 我不知道。如果我遇到任何事情会在这里发表评论。
    • 非常感谢。当您从其他框架迁移时的一些期望:P
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-23
    • 1970-01-01
    • 2011-07-27
    • 1970-01-01
    • 2013-02-16
    • 1970-01-01
    相关资源
    最近更新 更多